This article demonstrates three approaches for storing tree like structures with NoSQL databases with example of MongoDB.
|
use TreeMongo;
db.categoriesPCO.insert({_id:"Electronics",parent:null});
db.categoriesPCO.insert({_id:"Cameras_and_Photography",parent:"Electronics", order:10});
db.categoriesPCO.insert({_id:"Digital_Cameras",parent:"Cameras_and_Photography", order:10});
db.categoriesPCO.insert({_id:"Camcorders",parent:"Cameras_and_Photography", order:20});
db.categoriesPCO.insert({_id:"Lenses_and_Filters",parent:"Cameras_and_Photography", order:30});
db.categoriesPCO.insert({_id:"Tripods_and_supports",parent:"Cameras_and_Photography", order:40});
db.categoriesPCO.insert({_id:"Lighting_and_studio",parent:"Cameras_and_Photography", order:50});
db.categoriesPCO.insert({_id:"Shop_Top_Products",parent:"Electronics", order:20});
db.categoriesPCO.insert({_id:"IPad",parent:"Shop_Top_Products", order:10});
db.categoriesPCO.insert({_id:"IPhone",parent:"Shop_Top_Products", order:20});
db.categoriesPCO.insert({_id:"IPod",parent:"Shop_Top_Products", order:30});
db.categoriesPCO.insert({_id:"Blackberry",parent:"Shop_Top_Products", order:40});
db.categoriesPCO.insert({_id:"Cell_Phones_and_Accessories",parent:"Electronics", order:30});
db.categoriesPCO.insert({_id:"Cell_Phones_and_Smartphones",parent:"Cell_Phones_and_Accessories", order:10});
db.categoriesPCO.insert({_id:"Headsets",parent:"Cell_Phones_and_Accessories", order:20});
db.categoriesPCO.insert({_id:"Batteries",parent:"Cell_Phones_and_Accessories", order:30});
db.categoriesPCO.insert({_id:"Cables_And_Adapters",parent:"Cell_Phones_and_Accessories", order:40});
db.categoriesPCO.insert({_id:"Nokia",parent:"Cell_Phones_and_Smartphones", order:10});
db.categoriesPCO.insert({_id:"Samsung",parent:"Cell_Phones_and_Smartphones", order:20});
db.categoriesPCO.insert({_id:"Apple",parent:"Cell_Phones_and_Smartphones", order:30});
db.categoriesPCO.insert({_id:"HTC",parent:"Cell_Phones_and_Smartphones", order:40});
db.categoriesPCO.insert({_id:"Vyacheslav",parent:"Cell_Phones_and_Smartphones", order:50});
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
Web Developer, interested in bleeding age web technologies and projects.
Experienced and interested in:
- High load web projects, bespoke software development
- DevOps: Chef, Ansible, Vagrant
- NoSQL (mongodb)
- Client stack (javascript core, jquery, AngularJS, HTML5 apis)
- *AAS (Amazon beanstalk, Redhat openshift)
- MEAN & Pure JS stack (Javascript, AngularJS, Node.JS, MongoDB)
->
DevOps inquiries
->
Other inquiries
->
Follow me on Github