Skip to content

Instantly share code, notes, and snippets.

@bnoguchi
Created June 9, 2011 09:09
Show Gist options
  • Save bnoguchi/1016392 to your computer and use it in GitHub Desktop.
Save bnoguchi/1016392 to your computer and use it in GitHub Desktop.
Example showing that mongoose GH-301 is now irrelevant
var mongoose = require('mongoose')
, Schema = mongoose.Schema
, ObjectId = mongoose.SchemaTypes.ObjectId
, should = require('should');
mongoose.connect('mongodb://localhost/test');
var CommentSchema = new Schema({
id : ObjectId,
user : String,
title : String,
body : String,
dateadded : Date
});
var EntrySchema = new Schema({
id : ObjectId,
user : String,
title : String,
body : String,
shared : Boolean,
comments : [CommentSchema],
dateadded : Date
});
var Comment = mongoose.model('Comment', CommentSchema);
var Entry = mongoose.model('Entry', EntrySchema);
var entry = new Entry();
entry.comments.push({user: 'fake_steve_jobs', title:'test comment title1', body: 'test comment body1', dateadded: new Date()});
//console.log(entry.comments);
entry.save(function (err) {
should.strictEqual(null, err);
Entry.findById(entry._id, function (err, found) {
should.strictEqual(null, err);
found.comments.push({ user: 'brian', title: 'should work', body: 'GH-301 works', dateadded: new Date});
found.save( function (err) {
should.strictEqual(null, err);
mongoose.disconnect();
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment