Skip to content

Instantly share code, notes, and snippets.

@aheckmann
Created December 8, 2011 22:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aheckmann/1449032 to your computer and use it in GitHub Desktop.
Save aheckmann/1449032 to your computer and use it in GitHub Desktop.
var mongoose = require('mongoose');
mongoose.connect('localhost', 'test');
mongoose.set('debug', true)
var Foo = new mongoose.Schema({
name: { type: String
, index: { unique: true, background: true }
}
}, { collection: 'a'});
var A = mongoose.model('a', Foo);
mongoose.connection.on('error', function (err) {
// will show the index error
console.log('connection err', err);
})
mongoose.connection.on('open', function () {
console.log('running query...');
A.find().run(function (err, docs) {
console.log('\nquery error? %s', !! err, err && err.stack || '')
// returns 101 docs instead of all in the collection
console.log('returned %d docs', docs && docs.length || 0)
mongoose.disconnect();
})
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment