From dc4c979d340ba5ccedc68cedef0b7195ad998ac6 Mon Sep 17 00:00:00 2001 From: Dimitris Halatsis Date: Sat, 30 Jan 2016 13:21:40 +0200 Subject: [PATCH] added $elemMatch query operator support --- lib/model.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/lib/model.js b/lib/model.js index 89aec96..6d53d87 100755 --- a/lib/model.js +++ b/lib/model.js @@ -622,7 +622,20 @@ comparisonFunctions.$size = function (obj, value) { return (obj.length == value); }; +comparisonFunctions.$elemMatch = function(obj,value){ + if (!util.isArray(obj)) { return false; } + var i = obj.length; + var result = false; // Initialize result + while(i--){ + if (match(obj[i],value)){ // If match for array element, return true + result = true; + break; + } + } + return result; +}; arrayComparisonFunctions.$size = true; +arrayComparisonFunctions.$elemMatch = true; /**