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.
676 B
676 B
Mongo - Advanced Find
Lesson Objectives
- Explain Field Selection
- Explain Ordering
- Explain Paging
- Explain Count
Explain Field Selection
db.employees.find({}, {name: 1});- 1 for include
- 0 for exclude
{name:1, _id: 0}excludes _id
Explain Ordering
db.employees.find().sort({name: 1, salary: -1})- 1 for ascending
- -1 for descending
- won't sort on large set without index
Explain Paging
db.employees.find().sort({weight: -1}).limit(2).skip(1)- can help avoid issues when sorting on large un-indexed fields
Explain Count
db.employees.find({salary: {$gt: 50}}).count()- usual count is just a shortcut to this