Skip to content

Instantly share code, notes, and snippets.

@troygoode
Created May 14, 2011 14:28
Show Gist options
  • Save troygoode/972267 to your computer and use it in GitHub Desktop.
Save troygoode/972267 to your computer and use it in GitHub Desktop.
Number type is broken in Mongoose 1.3.3
// Setup Schema
// ------------
var
mongoose = require('mongoose'),
Schema = mongoose.Schema;
mongoose.model('Bug', new Schema({
someNumber: Number
}));
var Bug = mongoose.model('Bug');
mongoose.connect('mongodb://localhost/mongoosebug');
// Create new instance of Bug and increment the number field
// ---------------------------------------------------------
var newBug = new Bug();
newBug.someNumber = 4;
newBug.save(function(err, createdBug){
if(err) throw err;
Bug.findById(createdBug.id, function(err, found){
if(err) throw err;
found.someNumber = 10;
//running mongosniff shows that this save never executes
found.save(function(err, saved){
if(err) throw err;
//you would expect .someNumber to be 10
// - console.log instead prints out the json structure
// - and querying the db reveals the value is still 4
console.log(saved.someNumber);
mongoose.disconnect();
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment