I think you've mis-used .createIndex() here. { rating: 8 } is analogous to { rating: 1 }, which is an ascending index on the rating field. (-1 would be descending.) You needn't specify a value for the field that you are indexing on. The index encompasses all values.
Based on the video, I was going to ask if we had to create indexes for all ratings (or whatever values are valid for a property in a collection). Thanks for clarifying it's not needed.
Thanks for pointing this out. I was confused too because I saw that _id is indexed with value of 1 (which means include), so I was wondering why this one is using 8?!
@@hamza-325 Should be something like if you want asc order: BookSchema.index({ rating: 1 }, { name: 'rating_8_index', partialFilterExpression: { rating: 8 } });
thank you so much sensei for all your efforts..! I'm a proud learner ! While creating indexes, we don't have to specify any column with some specific value rather the docs suggests that indexes should be used as following : db.books.createIndex({rating: 1}) where 1 refers to ASC and -1 refers to DESC order. execution stats clearly shows the difference in execution.
I am not sure if this explanation is correct. Usually we create indexes for the entire domain of values. db.books.createIndex({rating:1}) will sort in the ascending order, and db.books.createIndex({rating:-1}) in descending order. I do not know if it supports partial indexes only for a specific field value.
Yep. You're absolutely right. This is easy enough to test. If you make and index on ratings: 8 and then do a query for ratings: 1 you'll see that the same index is used AND that the total records evaluated are equal to the number that are returned.
Just looking on RUclips for a MongoDB index tutorial and delight to hear the voice of The Net Ninja and be like oooooh, this guy covers MongoDb.... yoink. Thanks for this.
Great Video Shaun. As an Oracle DBA learning MongoDB, I particularly liked the section on indexes and explain('executionStats') to see if its using an index or doing a full scan. Thanks very much for this series. For very big collections, partitions would be worth considering too.
How can i find the difference of Timestamp field for two documents in the given collection where msgID field is same in both documents in the same collection.
First , Thank you for all these lessons ! and i wanted to ask u a question , is it better and less expensive to use mongoDb self hosted than mongoDb Realm for a React Native app ? Thanks in advance !
I think you've mis-used .createIndex() here. { rating: 8 } is analogous to { rating: 1 }, which is an ascending index on the rating field. (-1 would be descending.)
You needn't specify a value for the field that you are indexing on. The index encompasses all values.
ya I was also confused on that part, thanks.
Based on the video, I was going to ask if we had to create indexes for all ratings (or whatever values are valid for a property in a collection). Thanks for clarifying it's not needed.
Thank you guy for clarifying it, I was messed up with this "8" while reading Mongo documentation.
Thanks for pointing this out. I was confused too because I saw that _id is indexed with value of 1 (which means include), so I was wondering why this one is using 8?!
@@hamza-325 Should be something like if you want asc order:
BookSchema.index({ rating: 1 }, { name: 'rating_8_index', partialFilterExpression: { rating: 8 } });
thank you so much sensei for all your efforts..! I'm a proud learner !
While creating indexes, we don't have to specify any column with some specific value rather the docs suggests that indexes should be used as following :
db.books.createIndex({rating: 1}) where 1 refers to ASC and -1 refers to DESC order.
execution stats clearly shows the difference in execution.
I am not sure if this explanation is correct. Usually we create indexes for the entire domain of values. db.books.createIndex({rating:1}) will sort in the ascending order, and db.books.createIndex({rating:-1}) in descending order. I do not know if it supports partial indexes only for a specific field value.
Yep. You're absolutely right.
This is easy enough to test. If you make and index on ratings: 8 and then do a query for ratings: 1 you'll see that the same index is used AND that the total records evaluated are equal to the number that are returned.
I'm a bit disappointed to see you ignoring all the comments explaining that this tutorial is incorrect and responding to more recent positive comments
true :(
Just looking on RUclips for a MongoDB index tutorial and delight to hear the voice of The Net Ninja and be like oooooh, this guy covers MongoDb.... yoink. Thanks for this.
Great Video Shaun. As an Oracle DBA learning MongoDB, I particularly liked the section on indexes and explain('executionStats') to see if its using an index or doing a full scan. Thanks very much for this series. For very big collections, partitions would be worth considering too.
this is probably the best short explanation of mongodb indexes
Thanks Bohdan!
My favorite teacher. Thanks man ❤️
Thank you so much! came here from the garbage mongodb "university" course to get things straight.
Great stuff, keep it up!
This is the best mongo DB tutorial thanks dude
Perfect explaining, thanks a lot 🙏🏻!
Glad it was helpful!
Love the tutorials 😍. Thanks for creating this series, can you please expand it for Type script and optimising Mongo queries
If I am not wrong, Indexing is similar to sorting!!
Thank you Shaun!
can we have multiple indexes? lets say for same collection, an a book id and book rating?
Thank you
Is this playlist completely here??
thanks
How can i find the difference of Timestamp field for two documents in the given collection where msgID field is same in both documents in the same collection.
Great
Hello there Sir greetings.
Could it be possible for me to ask you a question, when ever I got stuck on implementing something?
First , Thank you for all these lessons !
and i wanted to ask u a question ,
is it better and less expensive to use mongoDb self hosted than mongoDb Realm for a React Native app ?
Thanks in advance !
if you need offline first application, then use Realm
if I want both offline and online. How can I use sir?
@@AdhimaFauzan
{2024-02-29}
thank you