Querying by field in MongoDB, which can be arbitrarily deeply nested in the document -


i developing restful api/thinking implementation. sake of simplicity, in model, there's document type, called 'box'. box can contain items, , other boxes well. (kind of composite pattern) such sub-boxes can arbitrarily nested.

in mongodb, such box document this:

{     _id: 0,     items: ['a', 'b', 'c'],     sub-boxes: [         {             _id: 1,             items: ['d', 'e']         },         {             _id: 2,             items: []             sub-boxes: [                 {                     _id: 3,                     items: ['g']                 }             ]         }     ] } 

my rest api url looks this: /api/boxes/:id

i able retrieve box #0 same way #3 (from api point of view).
/api/boxes/0
/api/boxes/3

my question is possible in mongodb query field _id, if don't know how nested in document? cannot hardcode in queries location of _id, since can anywhere.

i know normalize model, each 'sub-boxes' property contain references other boxes, prefer keep model denormalized, if possible.

in end decided normalize data, each box contains references other boxes.


Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -