MongoDB update deeply nested array -



MongoDB update deeply nested array -

consider next document:

{ "comments": [ { "id" : 1, "userid": "john", "comment": "lorem ipsum...", "responses": [ { "id" : 2, "userid": "smith", "comment": "lorem ipsum...", "responses": [ { "id" : 3, "userid": "random", "comment": "lorem ipsum...", "responses": [] // want force comment array }, { "id" : 4, "userid": "guy", "comment": "lorem ipsum..." } ] }, { "id" : 5, "userid": "adam", "comment": "lorem ipsum..." } ] } ] }

is there way force document responses array? in case user wants comment on level-3 comment , want force comment array. send array positions user , server when commenting i'm pretty sure that's unreliable. if delete happen in between (i guess(?)) positions alter in array, it's no-go.

if know sequence of indexes downwards level, yes:

> db.test.update({ ... }, { "$push" : { "comments.0.responses.0.responses.0.responses" : "this response" } })

the 0's indexes. however, multiply nested construction bad info modeling choice. should consider other options. perhaps docs on modeling tree structures helpful?

mongodb

Comments

Popular posts from this blog

assembly - What is the addressing mode for ld, add, and rjmp instructions? -

vowpalwabbit - Interpreting Vowpal Wabbit results: Why are some lines appended by "h"? -

ubuntu - Bash Script to Check That Files Are Being Created -