Skip to content

Instantly share code, notes, and snippets.

@aheckmann
Created October 14, 2011 14:34
Show Gist options
  • Save aheckmann/1287292 to your computer and use it in GitHub Desktop.
Save aheckmann/1287292 to your computer and use it in GitHub Desktop.
var mongoose = require('./mongoose');
mongoose.connect('localhost', 'testing_546');
var ObjectID = mongoose.Types.ObjectId;
var User = new mongoose.Schema({
nickname : { type: String, index: true, unique: true }
, _avatar : { type: mongoose.Schema.ObjectId, ref: 'Avatar' }
});
var A = mongoose.model('F', User);
mongoose.connection.on('open', function () {
A.create({ '_avatar': new ObjectID }, function (err, a) {
if (err) return console.error(err.stack||err);
var condition = { _id: new ObjectID(a.id) }
, doc = { _avatar: new ObjectID('4e8474d0098b5e0000000001') }
, options = { multi: false };
A.update(condition, doc, options, function (err) {
if (err) return console.error(err.stack||err);
A.findById(a._id, function (err, ret) {
if (err) return console.error(err.stack||err);
console.error(ret);
console.error(doc._avatar.toString() === ret._avatar.toString());
mongoose.connection.db.dropDatabase(function () {
mongoose.connection.close();
});
})
});
})
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment