c# - Working with hierarchical data in Mongo -
note: ended answering own question shortly after posting this. , sorry if spent time reading rediculously long post.
introduction
i'm sort of mongo noob, trying hang of things here.
i looking @ trying create hierarchical data structure can add nodes/leaves dynamically. schema fixed, nodes on given tree should able change @ time. main thing i'm looking how add/remove nodes on nested nodes without rewriting whole tree.
here'es example static analysis program, collection called "builds". sparse document (_id's removed brevity's sake):
{ name: "build changeset #5678", assemblies: [ { name: "someassembly1.dll", warnings: [ { level: 0, message: "something doesn't conform our standard" } ] } ] }
kick off, following;
db.builds.insert({name: "build changeset #5678})
then, add assembly:
db.builds.update({name: "build changeset #5678"}, {$addtoset: {assemblies: {name: "someassembly1.dll"}}})
the real question
now, how add warning? thinking might this:
db.builds.update({ name: "build changeset #5678", "assemblies.name": "someassembly1.dll" },{ $addtoset: { assemblies.warnings: { level: 0, name: "something doesn't conform our standard" } } })
but gives me "missing : after property id (shell):0"
tried putting quotes around "assemblies.warnings", says "can't append array using string field name [warnings]"
does know mongo better , can me?
am wrong in trying nested trees on mongo? better off doing multiple collections , relational?
under impression not doing relational (as acid) 1 of main benefits mongo, again, maybe thats noob showing again.
so i've been struggling day, , sure enough, moment post stackoverflow run across gives me answer. proper answer looks this:
db.builds.update({ name: "build changeset #5678", "assemblies.name": "someassembly1.dll" },{ $addtoset: { "assemblies.$.warnings": { level: 0, name: "something doesn't conform our standard" } } })
note the
"assemblies.$.warnings"
found here: http://groups.google.com/group/mongodb-user/browse_thread/thread/e8f4ea5dc1955a98#
Comments
Post a Comment