{
"city": "SF",
"state": "CA"
}
{
"state": "CA",
"city": "SF"
}
find({address: { city:"SF", state:"CA" }}) - bad
find({ 'address.city': "SF", 'address.state': "CA" }) - better
Sort specifiers
find().sort({ name: 1, _id: 1 })
!== find().sort({ _id: 1, name: 1 })
Collection indexes
collection.ensureIndex({ name: 1, address: 1 })
!==
collection.ensureIndex({ address: 1, name: 1 })
{
_id: "A",
ratings: [5, 1, 3]
},
{
_id: "B",
ratings: [2, 4, 9]
},
{
_id: "C",
ratings: [1]
}
{
_id: "A",
locations: [ [1, 2], [1, 0] ]
},
{
_id: "B",
locations: [ [ 0, 0 ] ]
}