So if there are 1000 comments and a new comment is added, the cloud function is going to query all 1000 comments. That is 'disturbing' for me. I wish they had a built-in collection size property.
@zuzelstein5 жыл бұрын
This should be top comment. Absolutely not production ready app. This is not cost effective to query all comments each time.
@RobertKing5 жыл бұрын
I suggest putting a "limit 100" on your query. that way it's production ready. Then in the user interface, if you get back 100, just show "100+". If you're getting more than 100 comments, you have other issues such as spam detection you need to take care of.
@b5a5m55 жыл бұрын
I may be mistaken for I haven't gone in depth in the docs but, is the "querySnapshot" not a reference to the documents that match the query from the indexes? Meaning the query isn't actually incurring a charge for reading the documents until forEach is executed?
@ScrubsFrance5 жыл бұрын
BAM5 size contains the number of documents returned firebase.google.com/docs/reference/android/com/google/firebase/firestore/QuerySnapshot.html#size() But it contains all the documents even before the foreach :( Have to limit the number of documents expected directly in the query request ;)
@otheraw56595 жыл бұрын
You can have the trick in the firebase channel. I forgot which videos, but I think it is one of the newest video about pricing. Basically you can just use math, save savedCommentsCount + 1 or something like that, u don't have to re-read all the doc in the collection
@basdfgwe6 жыл бұрын
Instead of reading all documents each time can you simply have a cloud function that increments a counter, and decrements based on a deletion.
@im.thatoneguy5 жыл бұрын
There is a danger of a race condition. If you have a user add and then a user delete smultaneously you could have a condition where they both start from the same document count and attempt to modify at once. Say we start at 100 posts -1 Delete. 99 posts. Now the Add function is also running in the background and it read the 100 posts before updating and your post count is now "101" instead of 100. It's still possible for the number to be off with parallel operators but it'll never be more off than the current number of active functions. If you have 9 people all try to delete simultaneously you might go from 100 -1 (9x times) and end up at 99 instead of 91 comments. Now when someone adds a document even if it was 99, it'll still recount and end back up at 92.
@basdfgwe5 жыл бұрын
@@im.thatoneguy hi Gavin, what if you did it with a transaction ?
@eric-id6bk3 жыл бұрын
@@basdfgwe This is a bit late, however, this wouldn't work. Transactions are not cross-user. You'd be best using a queue for the actions (increment, decrement) which invokes a cloud function and performs that action on that document. That way you'd only be writing to that content one at a time.
@dionricky3 жыл бұрын
For anyone looking for answer to this, maybe you can just increment/decrement the counter based on the action without even reading all the comments doc. But for certain interval, update the counter to match the size of comments in the firestore. This way is more "cheap" but requires you to set up another service for scheduling the counter "cache" refresh job. Edit: race condition on post-comment case is totally fine. But if you need something more reliable, for ticket reservation for example, probably use SQL instead of NoSQL db.
@basdfgwe3 жыл бұрын
@@dionricky hi Don, I didn't think there was a way of getting a count like what we have in SQL.
@drantunes6 жыл бұрын
Use a limit(5) query in comments collection seems more simple, or no?
@saadabbasi20635 жыл бұрын
Hey Diago, Good approach, but correct me if i am wrong. Till this point that "we need to isolate reviews/comments in to a separate model" we are on the same channel, right? If we query by limit on othher document then n of population queries will be made to reviews/comments collection (here n is number of posts) and reffing in mongodb is not thhat performant as Joins in SQL. Is that still a good approach, if you could share your thoughts
@tntg54 жыл бұрын
I have a similar feature but I don't nest comments under the parent collection. Instead, I have a separate collection at the root that is called comments, and have a property called parentId. That is because a comment can be attached to a post or event or some other object. Then when I call a post, I also make another call to comments with the post id, order desc, and limit to 5. But if I needed to display the number of comments it would be different
@johanchouquet28725 жыл бұрын
Thanks a lot Jeff! Could you prepare a video where you have to do Transaction in Cloud Functions for aggregation of a counter for example in order to prevent contention on multiple accesses on data ? It's a really common use case, and there's few docs about this on the web!
@RafaelTorquato2 жыл бұрын
This solution works well with 1s limit on the updates of a document?
@krisnaldoHD6 жыл бұрын
Is this not as insufficient as reading all of the comments and then counting the number of objects? Or is it different when you're doing this on the server side?
@artursponchiado72656 жыл бұрын
Good video! But I was thinking, does the firestore don't have a limit of 1 transaction/update per second? Even if I wrap all that code in a transaction, it will be limited by this 1sec update limit, right?
@KosratDAhmad-ti4qy6 жыл бұрын
event.params doesn't exist from DocumentSnapshot??
@whatthefunction91403 жыл бұрын
If I have 1 million documents and want to delete 500k Oldest is that one delete or 500k deletes?
@pandarzzz6 жыл бұрын
Thank you for sharing this informative video! 🐋🖐🏾 I find this video very useful. I hope you are well.
@RageBasterd6 жыл бұрын
excellent content as always my feed is full of firebase today, with all this dev summit and waht not. to bad most of it is for native mobile
@Fireship6 жыл бұрын
Thank you! Bunch of great content right now, hard to keep up.
@niyongaboeric6 жыл бұрын
Special Angular Men Thank you.
@Fireship6 жыл бұрын
Thank you!
@TimeoutMegagameplays5 жыл бұрын
1:48 What would be ideal for something that would get as many reads as writes?
@POSITIVO5096 жыл бұрын
Amazing
@jajasaria5 жыл бұрын
i know mysql but why nosql look so hard to me. hope someone could help me.
@or.o.s.t81903 жыл бұрын
How does he write in batches (not letter by letter)? I assume it's done in editing but could there be an extension for vscode/some other magic in play?
@crowdozer35923 жыл бұрын
I'm not 100% sure how he's doing it, maybe editing, but I also vaguely recall there being an extension that does something similar to this for demonstrative purposes. I remember a coworker saying it'd be funny to troll someone by pretending to be doing something super complex super fast with it
@crowdozer35923 жыл бұрын
Given the mouse movements I'm more inclined to think it is actually an extension
@zacturner78946 жыл бұрын
Is this code still valid? I get a log error on the server that 'commentId' and 'postId' are trying to call on undefined ie ( 'event.params'). Any ideas?
@Fireship6 жыл бұрын
For the most part yes, but there were some changes in v1.0 that is causing your error firebase.google.com/docs/functions/beta-v1-diff
@zacturner78946 жыл бұрын
@@Fireship Thanks mate, got it sorted.
@JeffrinJ6 жыл бұрын
What Operation system are you using?
@erperejildo5 жыл бұрын
but where is that index.js located?
@boon_keng5 жыл бұрын
Firestore support createdAt ordering?
@primeraposicion6 жыл бұрын
Thank you { while (true) { n * 'so' } } much!! :D
@mozartzerna70246 жыл бұрын
i have this error Cannot read property 'commentId' of undefined ? need help?
@ngrund16 жыл бұрын
You are using a newer version of Firebase SDK for Cloud Functions than he is in this video. Check out the changes needed: firebase.google.com/docs/functions/beta-v1-diff. Here is how I changed the code he provided to get this working: const functions = require('firebase-functions'); const admin = require('firebase-admin'); admin.initializeApp(); exports.aggregateComments = functions.firestore .document('posts/{postId}/comments/{commentId}') .onWrite((change, context) => { const commentId = context.params.commentId; const postId = context.params.postId; Pretty much the same from there on out.
@murthy9006 жыл бұрын
how to add new subcollection from angular ?
@Nek2085 жыл бұрын
How would you solve relationship? Example: see userName or userPhoto on every comment?
@nickstylezmedia5 жыл бұрын
kzbin.info/www/bejne/oJ6ZZ4eJobunmcU :)
@saffanalvy2 жыл бұрын
Hi. Can you please make this process in Flutter for Android section. I'll highly appreciate it. Thanks.
@niyongaboeric6 жыл бұрын
Hi Jeff, I may you advise me the level of typescript I must have to start developing SPA. Thanks
@harpymaslow6 жыл бұрын
You rock. Gotta take the pro stuff. Don't want to pay every month though. Is the 40% offer still up for the one-time purchase ? Thx man
@Fireship6 жыл бұрын
Thank you! The one-time membership is not currently discounted, but the monthly/quarterly is. You can cancel anytime. But with the lifetime you also get a free t-shirt :)
@harpymaslow6 жыл бұрын
Angular Firebase Ah the t-shirt. See I need the lifetime plan ^^ The discount was only during Google I/O ?
@Fireship6 жыл бұрын
Yes, but I will likely discount it again in the future. Not definite timeline tho.
@harpymaslow6 жыл бұрын
Angular Firebase Ok. I'll wait for it then. Great job on the videos. You're helping a LOT
@game-o-zone81706 жыл бұрын
Everything you teach is too good, only thing is you have to slow down a bit, and explain it in depth. rest everything seems gr8 :)
@ashb92546 жыл бұрын
he thinks he is teaching to experts
@ImperiumLibertas6 жыл бұрын
Most of these videos are directed towards those who are "experts." If you want to learn angular, he has a beginners tutorial series.
@sulaiman26066 жыл бұрын
Great work😍 Can you please provide us with the structure of this application
@Fireship6 жыл бұрын
Thank you! Follow the link in the description to get the full code on github.
@hirenpatelcr6 жыл бұрын
Super Fast.... cant understand.
@yeilmusic4 жыл бұрын
FAVOURITES, likes ? how to fetch which video like user.