Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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