Note: I ended up answering my own question shortly after posting this. Thanks and sorry if you spent time reading my rediculously long post.
Introduction
I’m sort of a Mongo noob, just trying to get the hang of things here.
I am looking at trying to create a hierarchical data structure to which i can add nodes/leaves dynamically. The schema is fixed, but the nodes on any given tree should be able to change at any time. The main thing I’m looking for is how to add/remove nodes on deeply nested nodes without rewriting the whole tree.
Here’es an example for a static analysis program, the collection is called “builds”. A sparse document would look like this (_id’s removed for brevity’s sake):
{ name: "build from changeset #5678",
assemblies: [
{ name: "someAssembly1.dll",
warnings: [
{ level: 0,
message: "something doesn't conform to our standard"
}
]
}
]
}
So to kick it off, I do the following;
db.builds.insert({name: "build from changeset #5678})
Then, add an assembly:
db.builds.update({name: "build from changeset #5678"},
{$addToSet: {assemblies: {name: "someAssembly1.dll"}}})
The REAL Question
Now, how do I add a warning?
I was thinking it might be something like this:
db.builds.update({
name: "build from changeset #5678",
"assemblies.name": "someAssembly1.dll"
},{
$addToSet: {
assemblies.warnings: {
level: 0,
name: "something doesn't conform to our standard"
}
}
})
But that gives me “missing : after property id (shell):0”
I also tried putting quotes around “assemblies.warnings”, but that says “can’t append to array using string field name [warnings]”
Does anyone know Mongo any better than I and can help me?
Am I wrong in trying to do deeply nested trees on Mongo? Would I be better off doing it with multiple collections and somewhat relational?
I was under the impression that NOT doing relational (as well as ACID) was one of the main benefits for Mongo, but then again, maybe thats just my noob showing again.
So I’ve been struggling with this all day, and sure enough, the moment I post it to StackOverflow I run across something that gives me the answer. The proper answer looks like this:
Note the
I found it here: http://groups.google.com/group/mongodb-user/browse_thread/thread/e8f4ea5dc1955a98#