Skip to content

Instantly share code, notes, and snippets.

@mchapman
Created June 27, 2014 19:20
Show Gist options
  • Save mchapman/078818d5229129c8cce5 to your computer and use it in GitHub Desktop.
Save mchapman/078818d5229129c8cce5 to your computer and use it in GitHub Desktop.
What gives?
var mongoose = require('mongoose');
console.log('\n===========');
console.log(' mongoose version : %s', mongoose.version);
console.log(' mongo driver version : %s', mongoose.mongo.version);
mongoose.set('debug', true);
mongoose.connect('localhost', 'findtest');
mongoose.connection.on('error', function () {
console.error('connection error', arguments);
});
var phoneSchema = mongoose.Schema({
which: {type: String, required : true, enum:['home','work','mobile']},
number: {type:String, required:true}
});
var personSchema = mongoose.Schema({
surname: String,
forename: String,
phones: {type : [phoneSchema]}
});
var Person = mongoose.model('person', personSchema);
mongoose.connection.on('open',function() {
var admin = new mongoose.mongo.Admin(mongoose.connection.db);
admin.buildInfo(function (err, info) {
if (err) throw err;
console.log(' mongodb info : %s', info.version);
console.log('========\n\n');
Person.remove({}, function(err){
if (err) throw err;
var person = new Person({surname: 'Bond', forename: ' James'});
person.save(function (err) {
Person.find({surname: { '$in': [ 'Bond', null ] },
givenName: { '$in': [ 'James', null ] },
'phones.number': { '$in': [ '01234 56789', null ] }
}, function (err, peopleList) {
if (err) throw err;
console.log("Number of possible dupes is " + peopleList.length);
done();
})
});
});
});
});
function done (err) {
if (err) console.error(err.stack);
mongoose.connection.db.dropDatabase(function () {
mongoose.connection.close();
});
}
@mchapman
Copy link
Author

Output from 2.6:

mongoose version     : 3.8.12
mongo driver version : 1.4.5
mongodb info         : 2.6.3

Mongoose: people.remove({}) {}
Mongoose: people.insert({ __v: 0, phones: [], _id: ObjectId("53adc3b6bec633a919dd3930"), forename: ' James', surname: 'Bond' }) {}
Mongoose: people.find({ surname: { '$in': [ 'Bond', '\u001b[1mnull\u001b[22m' ] }, givenName: { '$in': [ 'James', '\u001b[1mnull\u001b[22m' ] }, 'phones.number': { '$in': [ '01234 56789', '\u001b[1mnull\u001b[22m' ] } }) { fields: undefined }
Number of possible dupes is 0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment