Find a user whose email is verified. The "emails" field is an array. The function of "$elemMatch" operator is:
Find a element in an array (here is emails), whose feature obey the value after "$elemMatch" (here its "verified" key is "true").
The code:
> db.users.findOne({'emails': {$elemMatch: {verified: true}}})
{
"_id" : "rKawn5jCiuGcsPHdP",
"createdAt" : ISODate("2015-05-07T01:04:23.375Z"),
"services" : {
"password" : {
"bcrypt" : "$2a$10$T07N74DUrVrRtVGPT9dzleZlpRTlULfb9OrlWveW4NbcNpi.HkiAK"
},
"resume" : {
"loginTokens" : [
{
"when" : ISODate("2015-05-07T01:04:23.902Z"),
"hashedToken" : "Xbt2ASQF61artSmrYX1Gn6DLUNvbIrz9DW0sE4tbJh4="
}
]
},
"email" : {
"verificationTokens" : [ ]
}
},
"emails" : [
{
"address" : "leechau@126.com",
"verified" : true
}
]
}