annyoung

[mongodb] how to find dictionary not null 본문

데이터베이스

[mongodb] how to find dictionary not null

nopsled 2018. 4. 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"

    }

}


Comments