Skip to content

Instantly share code, notes, and snippets.

@ovaillancourt
Created May 14, 2012 22:29
Show Gist options
  • Save ovaillancourt/2697853 to your computer and use it in GitHub Desktop.
Save ovaillancourt/2697853 to your computer and use it in GitHub Desktop.
var mongoose = require('mongoose');
var Schema = mongoose.Schema;
var FooSchema = new Schema({
dob: { type: Date},
num: {type : Number},
test : {
bla : {type: Number}
}
});
FooSchema.virtual('virtualpath').get(function(){return 'Ima virtual';});
mongoose.connect("mongodb://test:test@127.0.0.1/test");
Foo = mongoose.model('Foo', FooSchema);
Foo.remove({}, function(err) {
var f;
f = new Foo({
dob: Date.now(),
num: 1,
test : {
bla: 2
}
});
f.save(function(err) {
Foo.find().$or([{'test.bla' : 2},{'test.bla' : 3}]).run(function(err, doc) {
console.log(doc);
});
});
});
@subchild
Copy link

Hey - I finally got to this but can't get it to return anything, even without the remove() call and verifying that there's data in the DB. The find().$or() call returns an empty set. Its as if its looking at the wrong collection.

@ovaillancourt
Copy link
Author

Hm, weird, I'm seeing the document in my console without any problem when I run this... What version of mongodb are you using? I know that the sub-document support for the $or operator has been added with mongodb 2, could be missing if you have < 2.0.

Poking @aheckmann, got an idea?

@subchild
Copy link

Thanks for the reply. It smells like a mongo version issue. Verifying now.

@ovaillancourt
Copy link
Author

Alright, keep me in the loop, I'd be curious to know the resolution of this issue.

@subchild
Copy link

All good after updating to mongodb 2.0.5. Sorry for the false alarm and thanks again for the help.

@ovaillancourt
Copy link
Author

My pleasure! Glad to hear it fixed it the issue :).

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