1

I have this document

{ "_id" : ObjectId("53c27ddf6f449b0572e8af95"), "Data" : [ [ { "_id" : 1, "Dados" : "dia:10:#mes:Outubro:#ano:1986:#hora:07:minuto:29:#segundo:16" } ] ] }

Tried this

db.data.find({ Data: {$in: {$elemMatch { _id: {$gte: 2}}}}})

and tried this

db.data.find({Data: {$elemMatch:{$elemMatch:{$in:[_id: 2]}}}})

none worked =\

what i want is to find the id = 1

I hope you guys can help me out, because i don't know what else to do. i tried this code from this link Querying an array of arrays Thanks for your attention.

Community
  • 1
  • 1
Reno
  • 2,639
  • 2
  • 12
  • 7

1 Answers1

2

You can do it like this:

db.data.find({"Data":{$elemMatch:{$elemMatch:{_id:1}}}})
dark_shadow
  • 3,503
  • 11
  • 56
  • 81
  • You can remove it. It will also work after removing the "". Actually its a good habit to put fields in "" because sometimes you might be using nested fields and in that case using the field without "" will cause an error. For now, you can remove it. – dark_shadow Jul 13 '14 at 15:54
  • Ah i see, thanks, i'll keep this habit, lets say i want to show everything, i should use db.data.find({"Data":{$elemMatch:{$elemMatch:{_id:{$gt:0}}}}}), right? There's another way ? That's my last question, and thanks you very much dark_shadow – Reno Jul 13 '14 at 16:23
  • What do you mean by show everything ? If you are trying to say you want all documents where _id > 0 then your query is right. – dark_shadow Jul 13 '14 at 16:28
  • Yes, show all documents, i have another problem now, should I post it here or ask another question? is about multiple auto_increment. – Reno Jul 13 '14 at 21:08
  • Your issue seems to be different then the existing issue. You should create a separate thread for it. – dark_shadow Jul 14 '14 at 05:23
  • Thanks for yout attention dark_shadow. i appreciate it. – Reno Jul 14 '14 at 15:22
  • Shot for that "" nested property tip. – Shaun Groenewald Jul 16 '15 at 09:29