[mongodb] how to find dictionary not null

Posted by nopsled
2018.04.30 18:17 데이터베이스

{

    "_id" : ObjectId("5a129bde1c6fcc3ea4d21db0"),

    "email" : "test@gmail.com",

    "name" : "test",

    "authType" : "google",

    "loc" : {

        "country" : "US"

    }

},


{

    "_id" : ObjectId("5a129bde1c6fcc3ea4d21db0"),

    "email" : "test2@gmail.com",

    "name" : "test2",

    "authType" : "google",

    "loc" : {}

},


{

    "_id" : ObjectId("5a129bde1c6fcc3ea4d21db0"),

    "email" : "test3@gmail.com",

    "name" : "test3",

    "authType" : "google",

    "loc" : {}

},


{

    "_id" : ObjectId("5a129bde1c6fcc3ea4d21db0"),

    "email" : "test4@gmail.com",

    "name" : "test4",

    "authType" : "google",

    "loc" : {

        "country" : "US"

    }

}


You have to know object's dictionary key.


If you want find loc(dictionary) not null data, using next query.


db.users.find({"loc.country":{$exists:true}}) 



debug result

{

    "_id" : ObjectId("5a129bde1c6fcc3ea4d21db0"),

    "email" : "test@gmail.com",

    "name" : "test",

    "authType" : "google",

    "loc" : {

        "country" : "US"

    }

},

{

    "_id" : ObjectId("5a129bde1c6fcc3ea4d21db0"),

    "email" : "test4@gmail.com",

    "name" : "test4",

    "authType" : "google",

    "loc" : {

        "country" : "US"

    }

}


이 댓글을 비밀 댓글로