pull/2/head
Louis Chatriot 12 years ago
parent a70f4babac
commit 24827f5ab0
  1. 12
      lib/model.js
  2. 12
      test/model.test.js

@ -328,6 +328,18 @@ comparisonFunctions.$ne = function (a, b) {
return !areThingsEqual(a, b);
};
comparisonFunctions.$in = function (a, b) {
var i;
if (!util.isArray(b)) { throw "$in operator called with a non-array"; }
for (i = 0; i < b.length; i += 1) {
if (areThingsEqual(a, b[i])) { return true; }
}
return false;
};
/**
* Match any of the subqueries

@ -459,7 +459,7 @@ describe('Model', function () {
// General behaviour is tested in the block about $lt. Here we just test operators work
describe('Other comparison operators: $lte, $gt, $gte, $ne', function () {
describe('Other comparison operators: $lte, $gt, $gte, $ne, $in', function () {
it('$lte', function () {
model.match({ a: 5 }, { a: { $lte: 6 } }).should.equal(true);
@ -485,6 +485,16 @@ describe('Model', function () {
model.match({ a: 5 }, { b: { $ne: 5 } }).should.equal(true);
});
it('$in', function () {
model.match({ a: 5 }, { a: { $in: [6, 8, 9] } }).should.equal(false);
model.match({ a: 6 }, { a: { $in: [6, 8, 9] } }).should.equal(true);
model.match({ a: 7 }, { a: { $in: [6, 8, 9] } }).should.equal(false);
model.match({ a: 8 }, { a: { $in: [6, 8, 9] } }).should.equal(true);
model.match({ a: 9 }, { a: { $in: [6, 8, 9] } }).should.equal(true);
(function () { model.match({ a: 5 }, { a: { $in: 5 } }); }).should.throw();
});
});

Loading…
Cancel
Save