Skip to content

Commit 127f293

Browse files
committed
adding shortid to support deeper trees
1 parent b88d134 commit 127f293

File tree

3 files changed

+201
-165
lines changed

3 files changed

+201
-165
lines changed

lib/tree.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
var Schema = require('mongoose').Schema;
22
var streamWorker = require('stream-worker');
3+
var shortId = require('shortid');
34

45
module.exports = exports = tree;
56

@@ -28,11 +29,11 @@ function tree(schema, options) {
2829
*/
2930
schema.add({
3031
parent: {
31-
type: Schema.ObjectId,
32+
type: String,
3233
set: function (val) {
33-
return (val instanceof Object && val._id) ? val._id : val;
34+
return (val instanceof Object && val._id) ? val._id.toString() : val;
3435
},
35-
index: true
36+
unique: true
3637
},
3738
path: {
3839
type: String,

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@
2020
"engine": "node >= 0.4.0",
2121
"dependencies": {
2222
"mongoose": "3.x.x",
23-
"stream-worker": "0.x.x"
23+
"stream-worker": "0.x.x",
24+
"shortid": "2.0.0"
2425
},
2526
"devDependencies": {
2627
"async": "0.x.x",

0 commit comments

Comments
 (0)