C
C
cat_crash2013-08-14 12:57:58
MongoDB
cat_crash, 2013-08-14 12:57:58

Mongo: How to select a part of a multidimensional array?

Please don’t beat me hard - I’m still an absolute noob in Mongo
. So, I have already “virtuously” learned how to select objects by exact match (for example, ID), but what stunned me is how to make a selection if complex multidimensional arrays are stored, but you need to select only those that match partially.
For example:

{'id':123
'response':{
'one':'one',
'two':{'two':'two'},
'type':'text'
}
},
{'id':1234
'response':{
'one':'one',
'three':{'three':'three'},
'type':'text'
}
}

if I write db.collection.find({'response':{'type':'text'}}) then NULL is returned

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Andrew D.Laptev, 2013-08-14
@cat_crash

You need to write like this:

db.collection.find({'response.type':'text'}})

docs.mongodb.org/manual/core/read/#fields-of-a-subdocument

A
Alexey, 2013-11-22
@Sterhel

This was a small test comment, thank you all.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question