Skip to content

Instantly share code, notes, and snippets.

@Hasstrup
Last active March 3, 2019 19:47
Show Gist options
  • Save Hasstrup/54d6ef0a742f56f1c1b511c1eae510e3 to your computer and use it in GitHub Desktop.
Save Hasstrup/54d6ef0a742f56f1c1b511c1eae510e3 to your computer and use it in GitHub Desktop.
// assuming something we had a collection called movies and movies has two categories, action, comedy,
// and comedy has three sections (kevin hart, mike epps, chris rock) and action has three sections (chuck norris, jet li, jackie chan).
// if we were going to insert a document (movie) into the movies collection.
let movieOne = { _id: "Jolade's movie log", path: null } // the path null marks this as a root node
const m = db.movies.insert(movieOne)
//to declare a node to the category
const a = db.movies.insert({ path: `,${m._id},`, _id: "Jolade's movie log (action)" })
// adding the path declares it as a subdocument of the the initial movie log
// to insert a new node into the action category
const c = db.movies.insert({ path: `,${m._id},${a._id},`, _id: 'Chuck Norris' })
// to insert a leaf node into the chuck norris, sub_catetgory,
const leafMovie = db.movies.insert({ path: `,${m._id},${a._id},${c._id},` name: "Killer Cam by Chuck")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment