Skip to content

Instantly share code, notes, and snippets.

@aheckmann
Created September 23, 2011 13:42
Show Gist options
  • Save aheckmann/1237353 to your computer and use it in GitHub Desktop.
Save aheckmann/1237353 to your computer and use it in GitHub Desktop.
var mongoose = require('./mongoose');
mongoose.connect('localhost', 'testing_516');
var ASchema = new mongoose.Schema({ 0: Number, 1: Number });
var A = mongoose.model('A', ASchema);
mongoose.connection.on('open', function () {
var a = new A;
a[0] = 100;
a['1'] = 200;
console.error('new', a);
a.save(function (err) {
if (err) return console.error(err.stack||err);
A.findById(a, function (err, a) {
if (err) return console.error(err.stack||err);
console.error('found', a);
console.error('a[0]: %d, a["0"]: %d, a[1]: %d, a["1"]: %d', a[0], a['0'], a[1], a['1']);
mongoose.connection.db.dropDatabase(function () {
mongoose.connection.close();
});
});
});
});
/**
* prints
*
* new { '0': 100, '1': 200, _id: 4e7c8d302e80a0645e000001 }
* found { '0': 100, '1': 200, _id: 4e7c8d302e80a0645e000001 }
* a[0]: 100, a["0"]: 100, a[1]: 200, a["1"]: 200
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment