Skip to content

Commit 0287a8a

Browse files
committed
updated readme
1 parent cb363b1 commit 0287a8a

File tree

2 files changed

+88
-13
lines changed

2 files changed

+88
-13
lines changed

README.md

Lines changed: 87 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,22 @@
1-
## mongoose-tree
1+
## mongoose-path-tree
22

3-
Implements the materialized path strategy for storing a hierarchy of documents with mongoose
3+
Implements the materialized path strategy with cascade child re-parenting on delete for storing a hierarchy of documents with mongoose
4+
Version with all collected features and fixes from mongoose-tree, mongoose-tree-fix, mongoose-tree2, mongoose-reparenting-tree
45

56
# Usage
67

78
Install via NPM
89

9-
$ npm install mongoose-tree
10+
$ npm install mongoose-path-tree
11+
12+
## Options
13+
14+
```javascript
15+
Model.plugin(tree, {
16+
pathSeparator : '#' // Default path separator
17+
onDelete : 'REPARENT' // Can be set to 'DELETE' or 'REPARENT'. Default: 'REPARENT'
18+
})
19+
```
1020

1121
Then you can use the plugin on your schemas
1222

@@ -56,14 +66,6 @@ At this point in mongoDB you will have documents similar to
5666

5767
The path is used for recursive methods and is kept up to date by the plugin if the parent is changed
5868

59-
## Options
60-
61-
```javascript
62-
Model.plugin(tree, {
63-
pathSeparator : '#' // Default path separator
64-
})
65-
```
66-
6769
# API
6870

6971
### getChildren
@@ -72,7 +74,7 @@ Signature:
7274

7375
getChildren([recursive], cb);
7476

75-
if recursive is supplied and true subchildren are returned
77+
if recursive is supplied and true, subchildren are returned
7678

7779
Based on the above hierarchy:
7880

@@ -86,6 +88,79 @@ adam.getChildren(true, function(err, users) {
8688
});
8789
```
8890

91+
### getChildrenTree
92+
93+
Signature:
94+
95+
getChildrenTree([args], cb);
96+
97+
return a recursive tree of subchildren.
98+
99+
args is an object you can defined with theses properties :
100+
101+
filters: mongoose query filter, optional, default null
102+
example: filters: {owner:myId}
103+
104+
fields: mongoose fields, optional, default null (all columns)
105+
example: columns: {"_id name owner"}
106+
107+
options: mongoose query option, optional, default null
108+
example: options:{{sort:'-name'}}
109+
110+
minLevel: level at which will start the search, default 1
111+
example: minLevel:2
112+
113+
recursive: boolean, default true
114+
make the search recursive or only fetch childs for the specified level
115+
example: recursive:false
116+
117+
allowEmptyChildren: boolean, default true
118+
if true, every childs not having subchilds will have childs attribute (empty array)
119+
if false, every childs not having subchilds will not have childs attribute
120+
121+
Example :
122+
123+
```javascript
124+
var args = {
125+
filters: {owner:myId},
126+
columns: {"_id name owner"},
127+
minLevel:2,
128+
recursive:true,
129+
emptyChilds:false
130+
}
131+
132+
getChildren(args,myCallback);
133+
```
134+
135+
Based on the above hierarchy:
136+
137+
```javascript
138+
adam.getChildren([function](err, users) {
139+
140+
/* if you dump users, you will have something like this :
141+
{
142+
"_id" : ObjectId("50136e40c78c4b9403000001"),
143+
"name" : "Adam",
144+
"path" : "50136e40c78c4b9403000001"
145+
"childs" : [{
146+
"_id" : ObjectId("50136e40c78c4b9403000002"),
147+
"name" : "Bob",
148+
"parent" : ObjectId("50136e40c78c4b9403000001"),
149+
"path" : "50136e40c78c4b9403000001.50136e40c78c4b9403000002"
150+
"childs" : [{
151+
"_id" : ObjectId("50136e40c78c4b9403000003"),
152+
"name" : "Carol",
153+
"parent" : ObjectId("50136e40c78c4b9403000002"),
154+
"path" : "50136e40c78c4b9403000001.50136e40c78c4b9403000002.50136e40c78c4b9403000003"
155+
}]
156+
}]
157+
}
158+
*/
159+
160+
});
161+
162+
```
163+
89164
### getAncestors
90165

91166
Signature:

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"url": "git://github.com/swayf/mongoose-path-tree.git"
1616
},
1717
"main": "index.js",
18-
"version": "1.0.0",
18+
"version": "1.0.1",
1919
"engine": "node >= 0.4.0",
2020
"dependencies": {
2121
"mongoose": "3.x.x"

0 commit comments

Comments
 (0)