0

I want to find a collection from below, with email condition: Below is my collections:

{
"_id" : ObjectId("59265694165bc936e998e314"),
"registrationToken" : null,
"temporaryInvitationId" : null,
"local" : {
    "password" : "$2a$10$xkNapVoNInR.FcGOqV4CjKYKV2hCWBzYIoufrFf2",
    "email" : "abc@gmail.com"
},
"__v" : 0,
"passwordResetToken" : null,
"profile" : {
    "referralId" : "r18YCPsgW",
    "_id" : ObjectId("597b7403aca04d1968823668"),
    "dietaryPreferences" : [ ],
    "referrerId" : "By2b4eKUb",
    "percentCommission" : 5
},
"lastLogin" : ISODate("2017-12-21T17:49:46.434Z")
},
{
"_id" : ObjectId("59265694165bc936e998e323"),
"registrationToken" : null,
"temporaryInvitationId" : null,
"local" : {
    "password" : "$2a$10$xkNapVoNInR.FcGOqV4CjKYKV2hCWBzYIoufrFf2",
    "email" : "xyz@gmail.com"
},
"__v" : 0,
"passwordResetToken" : null,
"profile" : {
    "referralId" : "r18YCPsgW",
    "_id" : ObjectId("597b7403aca04d1968823669"),
    "dietaryPreferences" : [ ],
    "referrerId" : "By2b4eKUb",
    "percentCommission" : 5
},
"lastLogin" : ISODate("2017-12-21T17:49:46.434Z")

}

I am using below query:

db.users.find( { "local": { email: "abc@hotmail.com" } } ).pretty()

But not able to get result. Please suggest what to do for get result if email is equal to 'abc@gmail.com'.

Thanks in advance

rohit13807
  • 605
  • 8
  • 19

2 Answers2

1

Simply use dot:

db.users.find({"local.email": "abc@hotmail.com"}).pretty()
wowkin2
  • 5,895
  • 5
  • 23
  • 66
1

You can use this query

db.col.find({"local.email" : "abc@gmail.com"})
Senthur Deva
  • 737
  • 4
  • 12