mongoDB笔记

MongoDB(filter数据筛选)

2017-11-25  本文已影响1942人  余生筑

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}})
上一篇下一篇

猜你喜欢

热点阅读