How to query for fields and fields in nested array

10 views
Skip to first unread message

Peter Tinder

unread,
Sep 12, 2015, 6:43:31 AM9/12/15
to Mongoose Node.JS ODM

I have a document like this:

{
    "InDate": "11.09.2015",
    "Kst2Kst": true,
    "OutDate": "11.09.2015",
    "__v": 0,
    "_id": ObjectId('55f2df2d7e12a9f1f52837e6'),
    "accepted": true,
    "inventar": [
        {
            "accepted": "1",
            "name": "AAAA",
            "isstammkost": true,
            "stammkost": "IWXI"
        },
        {
            "accepted": "1",
            "name": "BBBB",
            "isstammkost": false,
            "stammkost": "null"
        }
    ]
}

I want to select some data from the main document and the data with "isstammkost": true in the inventar-array.

                  
 Move.findOne({tablename: tablename, accepted : true, "inventar.isstammkost" : true}, 'OutDate InDate inventar.ean', {"inventar.$": 1}, function(err, res) {...

It doesn't work -> It selects all, even with inventar.isstammkost : false. The "normal" query works like I want (without criteria in nested array). Whats the right way to set criteria in nested array?

Reply all
Reply to author
Forward
0 new messages