Elad
Elad

Reputation: 51

Query array of arrays in Mongo

How would I query the the followoing: get the value of id '120154' for document '123' (result should be 32')

Collection Name:'Collection'

{
    "_id" : "123",
    "Data" : {
        "_v" : [ 
            [ 
                120154, 
                32
            ], 
            [ 
                120156, 
                "0.940515536000"
            ], 
            [ 
                120157, 
                ISODate("2013-12-26T00:00:00Z")
            ], 
            [ 
                120158, 
                "ABX-HE-AA 06-1"
            ], 
            [ 
                120159, 
                "0A08AG9A4"
            ]
]}}

Upvotes: 0

Views: 79

Answers (2)

M Omayr
M Omayr

Reputation: 1351

I had the same problem and so far I'm unable to find the solution because mongodb queries always return a whole document but you can project fields but that won't return you 32. So when you query {_id : 123} AND {no matter what else}, It will return you the matching whole documents not inner arrays.and I might be wrong but that's what I've experienced

Upvotes: 1

arunb2w
arunb2w

Reputation: 1196

db.collection.find({"_id" : "123"},{"Data._v.$1" : {"$in" : {120154}}}). I think this should work when u know the _id for the document.

Upvotes: 1

Related Questions