I have fetched data publicly to my blog from firebase database.
I wonder if this kind of thing could be done:
During search in blog, is it can bind together with the firebase fetched data? If it is can be done...then marvellous!
Thanks!
Extra info:
This is my sample blog.
As you can see, the list was fetched from firebase. I would like to let the user able to search on that list also.
The search area was at Cari area at the right top div.
Here..I tried to search something like this:
Related
I'd like to check if the user liking the post is already present in our users cloud Firestore.
There are two different collections here, need to check if one's reference is present in another.
Users collection has user details - UID/Name/Email
Posts collection has details : Post Text / Post Likes / Post Comments
Where Likes is an Map which has userId of person who has liked the image and userName.
From backend its possible to exploit the posts collection and enter malicious value in post documents.
I am trying to achieve this for ON UPDATE condition : To check the user liking post exists in users collection.
------ Tried Below So far but it doesnt work --------------------
match /posts/items/{document}
allow update: if exists(/database/$(database)/documents/users/$(request.resource.data.likes.userId));
What I want is to check if the users liking are already existing or not.
This doesnt work because the likes column is an array and can have multiple objects.
Any help would be great.
I am building a mobile app using Flutter and have several collections in my Firebase Database, such as userData, posts, chats, etc.
I refer to user's profile picture URL (which is stored in Firebase Storage) in the posts collection as well. If a user changes their profile picture, the URL is only directly updated in the userData collection. Is there an easy way to update the URL in the posts collection (and all the other collections that the URL is referred to) without let's say looping through all the posts and updating the URL wherever it's found?
Thanks for the help in advance!
without let's say looping through all the posts and updating the URL wherever it's found?
No, that's precisely what you're going to have to do, except you don't have to read all the documents. Just query for the ones that match what you need to change. Firestore doesn't have a "update where" type of query that can update multiple documents in a single operation.
One way to do it is saving the photo url only in the users collection like you do, then in the others collections you save the uid of the user instead of his photo url, finally, in the client side, you query the user data based on the uid, in this way you only need to save and update the photo url in one collection
I am building a social media database schema, in which I have users, followers, tags and posts. To conform to the firebase model I have flattened the structure as suggested in the firebase documentation as seen below. The issue that I am struggling with is when a user selects a tag and sees a bunch of posts from the tagPosts table all related by tag returned, I would then like to show the posts created by the current users followers first.
In SQL this would be done with an inline query checking the users followers, against the posts returned by a specific tag.
However in firebase I am not sure how do this without downloading all the posts contained under the tagID node in tagPosts and checking through each post's creator against the node of Followers for the current user userID. This operation could easily grow out of hand for 100s of posts amongst 100s of users. Ive tried modeling off of this answer, How do I check if a firebase database value exists? and this article From SQL to Firebase — How to structure the DB for a social network app. Am I poorly structuring the data how do I fix this thank you so much.
`
Users-
-userID1
-misc. userData
-userID2
-misc. userData
Followers-
-userID1
-userIDOfFollower1
-userIDOfFollower2
Following-
-userID1
-userIDOfFollower1
-userIDOfFollower2
Posts-
-postID1
-userIDFromCreator
-misc. PostData
Tags-
-tagID1
-misc. TagData
TagsUsers
-tagID1
-userID1
-userID2
TagsPosts
-tagID1
-postID1
-postID2
Edits-Thank you Frank
In our storyboard flow we plan to have a user see a wall of tags determined by constantly updating popular score based on properties of the tag and where we predict the user may have interest. The user will then select a tag and see posts related to that tag, from those posts I would like to show the posts from a users followers before those of everyone else who’s post falls in the category of a specified tag.
I have considered two possibilities either I optimize on reads in which I would have to keep track of every time a users follower posts to a tag and record the tagID along with the postID in a node for every follower a user has who posted in a special node of FollowersTags which would have a structure of listing for each userID a list of users and the all the followers of a user posted to which would become 100s of writes for each post created directly proportional to the number of followers a friend has.
*creates a list of posts to a specific tag made by followers
FollowersTags
-userID1_tagID1(composite key)
-postID1
-postID2
-postID3
-postID4
-userID1_tagID2
-postID1
-postID2
-postID3
-postID4
Or I could optimize on writes as tried above, which presents us with our current predicament of having to perform a query 100s of times directly proportional to the number of posts in a tag.
Is there any way around these two options which of the two is the better approach.
Unfortunately I would not be able to predict the posts displayed to the user before they select a tag.
In the Firebase Realtime Database, I typically model the data in the database to what I show on the screen. So if you have a "wall" of recent, relevant posts for each user, consider modeling precisely that in your database: a list of recent, relevant posts (or post IDs) for each user.
UserWalls
userID1
"timestamp_or_push_id": "postId1"
"timestamp_or_push_id": "postId2"
userID2
"timestamp_or_push_id": "postId1"
"timestamp_or_push_id": "postId3"
While the problem of determining what to show remains the same, with this database model it's now a write-time problem, instead of a read-time problem.
I want to search the "displayName" in documents nested within a collection, or more specifically the data is as follows:
users -> $idstring -> displayName
Ive come up with the following using AngularFire but its still not quite working for me.. I need to check displayName against the first 3 chars of val (user entered) and bring back results that start with that, I need a kind of LIKE search operation to occur, is this possible with firestore.. so far its just returning almost everything in my users collection
this.itemsCollection = this.aft.collection<iUser>('users', ref => ref.orderBy("displayName").startAt(val))
As mentioned on the Cloud Firestore Documentation:
Cloud Firestore doesn't support native indexing or search for text
fields in documents. Additionally, downloading an entire collection to
search for fields client-side isn't practical.
And to enable full text search of your data, you'd need to use a third-party search service like Algolia or ElasticSearch.
The documentation actually provides a guide on how to integrate Algolia with Firebase.
I'm learning angularjs, firebase, angularfire by building a sample app. It's a dictionary app that any one can add a word, add several explanation to the word, add several common usage to the word, add example centences to the word. People can freely add new word via this web app. OR people can freely realtime search a word and display the content of that word. When I build the app.
I found everytime when I search a word, I have to load all the data and then check if the query string exist in the data and then display the content if exist. So, it's quite heavy if the library become very big.
How can I query a string if it exist from the server side and if exist, just download that piece of data?
Here is a very simple example that is on the firebase site (Retreiving data). I suggest you take a look at that page, there is a lot more info there about this subject. Now the example:
var ref = new Firebase("https://dinosaur-facts.firebaseio.com/dinosaurs");
ref.orderByChild([the child node to compare to]).equalTo([what you are searching]).on("child_added", function(snapshot) {
//do something with the data in snapshot
});