Created
October 14, 2012 19:46
-
-
Save eethann/3889616 to your computer and use it in GitHub Desktop.
Mongoose Tree Schema
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// An excerpt from a Mongoose model.js file for use with Express: | |
// Sub-document to store parent ref along with it's value (a form of caching) | |
var Parent = new Schema({ | |
id: ObjectId | |
, text: String | |
}); | |
// Main tree-node element schema | |
var Branch = new Schema({ | |
text: { | |
type: String | |
, required: true } | |
, date: {type: Date, default: Date.now } | |
, trail: [Parent] | |
, parentBranchId: ObjectId | |
, parentBranch: { type: Schema.Types.ObjectId, ref: 'Branch' } | |
, _children: [{type: Schema.Types.ObjectId, ref: 'Branch'}] | |
// These two have been commented out because I have no clue how to best implement | |
// , _priorSiblings: { type: Schema.Types.ObjectId, ref: 'Branch' } | |
// , _followingSiblings: { type: Schema.Types.ObjectId, ref: 'Branch' } | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment