0

I have this structure

{
"_id" : "EbtLm2Nmb79WWryEr",
"notificationByUsers" : {
    "all" : [ 
        {
            "account_id" : "X5PjY66JAwgoxDb4L",
            "date" : ISODate("2016-07-27T13:48:17.154Z"),
            "value" : null
        }, 
        {
            "account_id" : "2C2FKXaKtmeRMNT3E",
            "date" : ISODate("2016-07-27T13:53:10.296Z"),
            "value" : "Instant"
        }, 
        {
            "account_id" : "6Np35oj63cavF4RHs",
            "date" : ISODate("2016-07-28T07:18:22.696Z"),
            "value" : "Instant"
        }
    ]
}

}

and i am querying

db.Collection.findOne({_id: EbtLm2Nmb79WWryEr, 'notificationByUsers.all':{$elemMatch:{account_id: "2C2FKXaKtmeRMNT3E"}}}, {_id:0, 'notificationByUsers.all.$': 1})

it returns in roboMongo

{
 "notificationByUsers" : {
"all" : [ 
    {
        "account_id" : "2C2FKXaKtmeRMNT3E",
        "date" : ISODate("2016-07-27T13:53:10.296Z"),
        "value" : "Instant"
    }
]
}

But in Meteor it returns all array elements with this query. I want the result with specific array element as working in robomongo.

2
  • Querying client or server side with Meteor? Commented Jul 28, 2016 at 8:43
  • Server Side Brother. Commented Jul 28, 2016 at 8:50

1 Answer 1

1

You can do this using fields projection, like:

MyCollection.findOne({},{ fields : {_id:0, 'notificationByUsers.all':1}});

This will return object like :

{
 "notificationByUsers" : {
"all" : [ 
    {
        "account_id" : "2C2FKXaKtmeRMNT3E",
        "date" : ISODate("2016-07-27T13:53:10.296Z"),
        "value" : "Instant"
    }
]
}
Sign up to request clarification or add additional context in comments.

2 Comments

"$err" : "Can't canonicalize query: BadValue >1 field in obj: { _id: 0.0, notificationByUsers.all.$: 1.0 }" in mongodb
This is the meteor way my friend.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.