Complete MongoDB Tutorial #24 - Indexes

Поделиться
HTML-код
  • Опубликовано: 17 ноя 2024

Комментарии • 45

  • @StevenSokulski
    @StevenSokulski 2 года назад +139

    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.

    • @daretobedangerous6552
      @daretobedangerous6552 Год назад +9

      ya I was also confused on that part, thanks.

    • @iatheman
      @iatheman Год назад +4

      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.

    • @dfdfdfdfddfdfdfdfdf9140
      @dfdfdfdfddfdfdfdfdf9140 Год назад +4

      Thank you guy for clarifying it, I was messed up with this "8" while reading Mongo documentation.

    • @hamza-325
      @hamza-325 Год назад

      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?!

    • @redpillsatori3020
      @redpillsatori3020 Год назад

      @@hamza-325 Should be something like if you want asc order:
      BookSchema.index({ rating: 1 }, { name: 'rating_8_index', partialFilterExpression: { rating: 8 } });

  • @MuhammadSaaddev
    @MuhammadSaaddev 2 года назад +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.

  • @piotrjan2927
    @piotrjan2927 2 года назад +23

    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.

    • @StevenSokulski
      @StevenSokulski 2 года назад

      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.

  • @jackwagstaffe9895
    @jackwagstaffe9895 Год назад +16

    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

  • @bovineox1111
    @bovineox1111 2 года назад

    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.

  • @malcolmfairs7752
    @malcolmfairs7752 2 года назад +1

    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.

  • @bkatsevych
    @bkatsevych Год назад

    this is probably the best short explanation of mongodb indexes

  • @donatusbrainokwe4350
    @donatusbrainokwe4350 2 года назад +3

    My favorite teacher. Thanks man ❤️

  • @tomervainshtein5863
    @tomervainshtein5863 Год назад

    Thank you so much! came here from the garbage mongodb "university" course to get things straight.
    Great stuff, keep it up!

  • @bakarymtraore6869
    @bakarymtraore6869 2 года назад +1

    This is the best mongo DB tutorial thanks dude

  • @zakaria5775
    @zakaria5775 Год назад

    Perfect explaining, thanks a lot 🙏🏻!

    • @NetNinja
      @NetNinja  Год назад

      Glad it was helpful!

  • @aiyushbedi
    @aiyushbedi 2 года назад

    Love the tutorials 😍. Thanks for creating this series, can you please expand it for Type script and optimising Mongo queries

  • @SaiBaba-zi5my
    @SaiBaba-zi5my 10 месяцев назад

    If I am not wrong, Indexing is similar to sorting!!

  • @ryanchristiansacdalan7104
    @ryanchristiansacdalan7104 2 года назад

    Thank you Shaun!

  • @Rohitsingh2410
    @Rohitsingh2410 4 месяца назад

    can we have multiple indexes? lets say for same collection, an a book id and book rating?

  • @abdellahiaioun8430
    @abdellahiaioun8430 11 месяцев назад

    Thank you

  • @Tony_stark551
    @Tony_stark551 5 месяцев назад

    Is this playlist completely here??

  • @fatimaiqra2169
    @fatimaiqra2169 2 месяца назад

    thanks

  • @NanduriSree
    @NanduriSree 2 года назад

    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.

  • @coderkashif
    @coderkashif Год назад

    Great

  • @xplore2000
    @xplore2000 2 года назад

    Hello there Sir greetings.
    Could it be possible for me to ask you a question, when ever I got stuck on implementing something?

  • @jhonlee788
    @jhonlee788 2 года назад +1

    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 !

    • @AdhimaFauzan
      @AdhimaFauzan Год назад

      if you need offline first application, then use Realm

    • @quangminh7474
      @quangminh7474 8 месяцев назад

      if I want both offline and online. How can I use sir?
      @@AdhimaFauzan

  • @patrikfiala498
    @patrikfiala498 5 месяцев назад

  • @Pareshbpatel
    @Pareshbpatel 8 месяцев назад +1

    {2024-02-29}

  • @farhanmirza52
    @farhanmirza52 9 месяцев назад

    thank you