In my mongodb collection, I have a collection with two levels of embedded documents.
Collection
- field1
- field2
- EmbeddedDocuments1
- field_a
- field_b
- EmbeddedDocument_a
- field_A
- field_B
- field_C
- EmbeddedDocuments2
- field_c
- field_d
- EmbeddedDocument_a
- field_D
- field_E
- field_F
- EmbeddedDocuments3
- field_e
- field_f
- EmbeddedDocument_a
- field_G
- field_H
- field_I
When I do a query to find a specific 2nd level document it takes a long time, ~= 500ms
The query I tried is something similar to the line below, which I only want to get the data from a 2nd level document.
db.collections.find({ "embedded_documents_1.embedded_documents_2._id":ObjectId("502e8f5565ce10780f00000c") })
However, this returns the entire one collection, which contains field1, field2, all EmbeddedDocuments
Am I doing something wrong here?