diff --git a/lib/adapters/mongodb.js b/lib/adapters/mongodb.js index 0d8edcffc..255522edc 100644 --- a/lib/adapters/mongodb.js +++ b/lib/adapters/mongodb.js @@ -289,6 +289,8 @@ adapter.findMany = function(model, query, projection) { }else if(key === 'or' || key === 'and') { query['$' + key] = _.map(val, parseQuery); delete query[key]; + }else if(key === '$or' || key === '$and'){ + query[key] = _.map(val, parseQuery); } }); diff --git a/test/fortune-mongodb/mongodb.spec.js b/test/fortune-mongodb/mongodb.spec.js index 9ebd80c9e..1448799db 100644 --- a/test/fortune-mongodb/mongodb.spec.js +++ b/test/fortune-mongodb/mongodb.spec.js @@ -434,6 +434,28 @@ module.exports = function(options){ done(); }); }); + it('should deeply parse nested $and, $or, or, and queries', function(done){ + var query = { + $or: [{ + or: [{ + $and: [{ + and: [{ + name: { + regex: 'WALLY', + options: 'i' + } + }] + }] + }] + }] + }; + adapter.findMany('person', query) + .then(function(docs){ + docs.length.should.equal(1); + docs[0].name.should.equal('Wally'); + done(); + }); + }); }); });