Skip to content

Instantly share code, notes, and snippets.

@trident523
Last active August 29, 2015 14:19
Show Gist options
  • Save trident523/0accaabd8c3afeebe415 to your computer and use it in GitHub Desktop.
Save trident523/0accaabd8c3afeebe415 to your computer and use it in GitHub Desktop.
IC - 438
db.categories.drop()
db.categories.insert( { _id: "MongoDB", parent: "Databases" } )
db.categories.insert( { _id: "dbm", parent: "Databases" } )
db.categories.insert( { _id: "Databases", parent: "Programming" } )
db.categories.insert( { _id: "Languages", parent: "Programming" } )
db.categories.insert( { _id: "Programming", parent: "Books" } )
db.categories.insert( { _id: "Books", parent: null } )
---
db.categories.find()
---
var databaseCategory = db.categories.findOne( { _id: "Computers" } );
db.categories.find( { left: { $gt: databaseCategory.left }, right: { $lt: databaseCategory.right } } );
use ProductListHW
db.categories.drop()
db.categories.insert({ "_id" : "Videos", "parent" : "Product List", "level" : "Category" })
db.categories.insert({ "_id" : "Classics", "parent" : "Videos", "level" : "SubCategory" })
db.categories.insert({ "_id" : "Comedies", "parent" : "Videos", "level" : "SubCategory" })
db.categories.insert({ "_id" : "Phones", "parent" : "Electronics", "level" : "SubCategory" })
db.categories.insert({ "_id" : "iPhone", "parent" : "Phones", "level" : "Item" })
db.categories.insert({ "_id" : "Samsung", "parent" : "Phones", "level" : "Item" })
db.categories.insert({ "_id" : "The African Queen", "parent" : "Classics", "level" : "Item" })
db.categories.insert({ "_id" : "The Maltese Falcon", "parent" : "Classics", "level" : "Item" })
db.categories.insert({ "_id" : "A Fish Called Wanda", "parent" : "Comedies", "level" : "Item" })
db.categories.insert({ "_id" : "What's Up Doc", "parent" : "Comedies", "level" : "Item" })
db.categories.insert({ "_id" : "Electronics", "parent" : "Product List", "level" : "Category" })
db.categories.insert({ "_id" : "Computers", "parent" : "Electronics", "level" : "SubCategory" })
db.categories.insert({ "_id" : "Lenovo", "parent" : "Computers", "level" : "Item"})
db.categories.insert({ "_id" : "Macbook", "parent" : "Computers", "level" : "Item" })
db.categories.insert({ "_id" : "Product List", "parent" : null})
---
db.categories.find()
---
var computerCategory = db.categories.findOne( { _id: "Computers" } );
db.categories.find( { left: { $gt: computerCategory.left }, right: { $lt: computerCategory.right } } );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment