Working with hierarchical data in Mongo



Note. In the end, I answered my question shortly after posting this. Thank you and sorry if you took the time to read my thoroughly long mail.



Introduction



I'm kind of a mongo noob, just trying to find things here.

I am looking for an attempt to create a hierarchical data structure to which I can add nodes / leaves dynamically. The layout is fixed, but nodes on any given tree should be able to change at any time. The main thing I'm looking for is to add / remove nodes on deeply nested nodes without overwriting the entire tree.

Here is an example of a static analysis program, the collection is called "builds". A rare document will look like this (_id removed for brevity):

{ name: "build from changeset #5678", 
  assemblies: [
    { name: "someAssembly1.dll",
      warnings: [
        { level: 0,
          message: "something doesn't conform to our standard"
        }
      ] 
    }             
  ]
}



Therefore, to drop this, I do the following:

db.builds.insert({name: "build from changeset #5678})


Then add the assembly:

db.builds.update({name: "build from changeset #5678"},
                 {$addToSet: {assemblies: {name: "someAssembly1.dll"}}})



? , - :

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"
   }
 }
})

"missing: after property id (shell): 0"

"assemblylies.warnings", , " []"


- ?

, ? ?

, ( ACID) , , , .

+3
1

, , , , StackOverflow, -, . :

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"
   }
 }
})

"assemblies.$.warnings"


: http://groups.google.com/group/mongodb-user/browse_thread/thread/e8f4ea5dc1955a98#

+2

Source: https://habr.com/ru/post/1766495/


All Articles