Skip to content

Commit

Permalink
Added ability to use $in conditional with Array types.
Browse files Browse the repository at this point in the history
  • Loading branch information
bnoguchi committed Feb 18, 2011
1 parent 196305f commit 1469c7c
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/mongoose/schema/array.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,9 @@ SchemaArray.prototype.$conditionalHandlers = {
, '$ne': function (val) {
return this.cast(val);
}
, '$in': function (val) {
return this.cast(val);
}
};
SchemaArray.prototype.castForQuery = function ($conditional, val) {
var handler;
Expand Down
20 changes: 20 additions & 0 deletions test/model.querying.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -634,6 +634,26 @@ module.exports = {
});
},

'test querying if an array contains one of multiple members $in a set': function () {
var db = start()
, BlogPostB = db.model('BlogPostB', collection);

var post = new BlogPostB();

post.tags.push('football');

post.save( function (err) {
should.strictEqual(err, null);

BlogPostB.findOne({tags: {$in: ['football', 'baseball']}}, function (err, doc) {
should.strictEqual(err, null);

doc._id.should.eql(post._id);
db.close();
});
});
},

'test querying via $which with a string': function () {
var db = start()
, BlogPostB = db.model('BlogPostB', collection);
Expand Down

0 comments on commit 1469c7c

Please sign in to comment.