user94628
user94628

Reputation: 3721

MongoDB return value from key in objects in array

I want to match the value of address, from an object of arrays holding objects:

email: {
  verified: [
    {
      token: "gCCt1IUKXPfB4Lj3q_t2vDfiUhis87Ki7mVuR3YLDRD",
      address: "[email protected]",
      when: ISODate("2017-01-06T11:40:22.293Z")
    }
  ]
}

This didn't work:

Meteor.users.findOne({email: {$elemMatch: {address: email}}})

How can you do it when there's an array to traverse?

Upvotes: 0

Views: 79

Answers (1)

Supradeep
Supradeep

Reputation: 3266

You've missed the array verified in your query, instead of $elemMatch you can just refer the object directly as shown below :

Meteor.users.findOne({"email.verified.address": email});

Upvotes: 1

Related Questions