You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
mongodb-lectures/4.MONGO_ADVANCED_FIND.md

676 B

Mongo - Advanced Find

Lesson Objectives

  1. Explain Field Selection
  2. Explain Ordering
  3. Explain Paging
  4. Explain Count

Explain Field Selection

  1. db.employees.find({}, {name: 1});
    • 1 for include
    • 0 for exclude
  2. {name:1, _id: 0} excludes _id

Explain Ordering

  1. db.employees.find().sort({name: 1, salary: -1})
    • 1 for ascending
    • -1 for descending
    • won't sort on large set without index

Explain Paging

  1. db.employees.find().sort({weight: -1}).limit(2).skip(1)
    • can help avoid issues when sorting on large un-indexed fields

Explain Count

  1. db.employees.find({salary: {$gt: 50}}).count()
    • usual count is just a shortcut to this