diff --git a/lib/finder.js b/lib/finder.js index f94ea8f..63bd2f0 100644 --- a/lib/finder.js +++ b/lib/finder.js @@ -728,7 +728,7 @@ var field = function (k) { s+= "v"+i+"="+ps+"\n"; s+= "if (!v"+i+") return null;\n"; if (path.length!=i) { - s+= "if (Array.isArray(v"+i+")) {\n"; + s+= "if (Array.isArray(v"+i+") && !(Number.isInteger(Number('"+path[i]+"')) && Number('"+path[i]+"') >= 0)) {\n"; s+= "for (i"+i+"=0; i"+i+"0) { if (k[0]=='$') diff --git a/test/search-array-test.js b/test/search-array-test.js index 6095f64..4da9573 100644 --- a/test/search-array-test.js +++ b/test/search-array-test.js @@ -44,7 +44,15 @@ describe('Search Array', function () { for (j=0; j<10; j++) { arr[j].sub.arr = arr2; } - obj = {num:i, pum:i, arr:arr, nags:["tag"+i,"tag"+(i+1)], tags:["tag"+i,"tag"+(i+1)], nested:{tags:["tag"+i,"tag"+(i+1)]}}; + obj = { + num:i, + pum:i, + arr:arr, + nags:["tag"+i,"tag"+(i+1)], + tags:["tag"+i,"tag"+(i+1)], + nested:{tags:["tag"+i,"tag"+(i+1)]}, + objectArray:[{tag:"tag"+i}] + }; coll.insert(obj, cb); i++; }, @@ -297,5 +305,11 @@ describe('Search Array', function () { done(); })); }); + it("find object array {'objectArray.0.tag':'tag1'} (no index)", function (done) { + coll.find({'objectArray.0.tag':'tag1'}).toArray(safe.sure(done, function (docs) { + assert.equal(docs.length, 1); + done(); + })); + }); }); });