-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathAncestorsReference_operating.js
More file actions
26 lines (18 loc) · 961 Bytes
/
AncestorsReference_operating.js
File metadata and controls
26 lines (18 loc) · 961 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
use TreeMongo;
print("inserting")
var ancestorpath = db.categoriesAAO.findOne({_id:'Electronics'}).ancestors;
ancestorpath.push('Electronics')
db.categoriesAAO.insert({_id:'LG', parent:'Electronics',ancestors:ancestorpath});
//{ "_id" : "LG", "parent" : "Electronics", "ancestors" : [ "Electronics" ] }
db.categoriesAAO.find({_id:'LG'})
print("updating/moving")
ancestorpath = db.categoriesAAO.findOne({_id:'Cell_Phones_and_Smartphones'}).ancestors;
ancestorpath.push('Cell_Phones_and_Smartphones')
db.categoriesAAO.update({_id:'LG'},{$set:{parent:'Cell_Phones_and_Smartphones', ancestors:ancestorpath}});
//{ "_id" : "LG", "ancestors" : [ "Electronics", "Cell_Phones_and_Accessories", "Cell_Phones_and_Smartphones" ], "parent" : "Cell_Phones_and_Smartphones" }
db.categoriesAAO.find({_id:'LG'});
//removing node
db.categoriesAAO.remove({_id:'LG'});
//getting children
print ("getting children")
db.categoriesAAO.find({$query:{parent:'Electronics'}})