美文网首页mongoDB笔记
MongoDB(filter数据筛选)

MongoDB(filter数据筛选)

作者: 余生筑 | 来源:发表于2017-11-25 19:52 被阅读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}})
    

    相关文章

      网友评论

        本文标题:MongoDB(filter数据筛选)

        本文链接:https://www.haomeiwen.com/subject/tomcbxtx.html