0

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"
            ]
]}}
1
  • 3
    I'm not sure that's possible, your schema abuses arrays. The inner arrays seem to be key-value pairs, so why not model them as such? Commented Jan 27, 2014 at 12:08

2 Answers 2

1

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

Sign up to request clarification or add additional context in comments.

Comments

1

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

Comments

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.