Read
Query on Embedded/Nested Documents
db.student.insertMany([
{
_id: 4,
name: "张兵",
age: 21,
score: {math : 80,history : 90 }
},
{
_id: 5,
name: "刘美",
age: 26,
score: {math : 90,history : 88 }
}
])
Specify query conditions on fields in an embedded/nested document with dot notation "field.nestedField". When you query with dot notation, the field and nested field must be inside quotation marks. The following example selects all documents where the field math nested in the score field equals 90:
db.student.find( { "score.math": 90 } )
The following query uses the less than operator ($lt) on the field math embedded in the score field:
db.student.find( { "score.math": { $lt: 81 } } )