Created
October 18, 2013 14:24
-
-
Save krevels/7042315 to your computer and use it in GitHub Desktop.
Mongoose: toJSON() on detached entities
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
var FeedSchema = new Schema({ | |
title: String, | |
description: String, | |
link: String, | |
rss: String, | |
pubdate: Date, | |
updated: { type: Date, default: Date.now }, | |
items: [{type: Schema.Types.ObjectId, ref: 'Item'}], | |
}); | |
var ItemSchema = new Schema({ | |
title: String, | |
description: String, | |
link: String, | |
source: String, | |
guid: String, | |
author: String, | |
pubdate: Date, | |
updated: { type: Date, default: Date.now }, | |
_feed: { type: Schema.Types.ObjectId, ref: 'Feed' } | |
}); | |
mongoose.model('Feed', FeedSchema); | |
mongoose.model('Item', ItemSchema); | |
------------- | |
var Feed = mongoose.model('Feed'); | |
var feed = new Feed(); | |
feed.items.push(new Item()); | |
console.log(feed.toJSON()); |
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
{ | |
"title": "BBC News - Home", | |
"description": "The latest stories from the Home section of the BBC News web site.", | |
"pubdate": "2013-10-18T01:30:10.000Z", | |
"link": "http://www.bbc.co.uk/news/#sa-ns_mchannel=rss&ns_source=PublicRSS20-sa", | |
"_id": "52609041036001b379000052", | |
"items": [ | |
"52609041036001b379000053" | |
], | |
"updated": "2013-10-18T01:34:57.167Z", | |
"created": "2013-10-18T01:34:57.000Z", | |
"id": "52609041036001b379000052" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment