db.users.find({filter})
*数据为{{},{},{}}形式
{
"_id" : ObjectId("5a194d5795063d2f7e6434a2"),
"name" : "jack",
"age" : 13,
"hobbies" : {
"surfing" : {
"desc" : "great"
},
"snowing" : {
"desc" : "bad"
}
}
}
查找方法
db.users.find({'hobbies.surfing.desc':'great'})
*数据为{[{},{},{}]}形式
{
"_id" : ObjectId("5a194942d97f41539378b81d"),
"name" : "jack",
"age" : 13,
"hobbies" : [
{
"name" : "hiking",
"level" : "great"
},
{
"name" : "snowing",
"level" : "bad"
}
]
}
查找方法
db.users.find({'hobbies.name':'hiking'})
- 数据为{[],[],[]}形式
{
"_id" : ObjectId("5a1949c8d97f41539378b81e"),
"name" : "zha",
"age" : 93,
"hobbies" : [
"hiking",
"snowing",
"eating"
]
}
查找方法
db.users.find({"hobbies.hiking":{$exists: true}})