Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -219,9 +219,15 @@ var matchers = {
return false;
}

if (typeof docFieldValue[0] === 'object' && docFieldValue[0] !== null) {
var userValueKeys = Object.keys(userValue);
var userValueHasNonOperator = userValueKeys.some(function (key) {
return key.indexOf('$') !== 0;
});

if (userValueHasNonOperator) {
return docFieldValue.some(function (val) {
return rowFilter(val, userValue, Object.keys(userValue));
return typeof val === 'object' && val !== null &&
rowFilter(val, userValue, userValueKeys);
});
}

Expand Down
20 changes: 20 additions & 0 deletions tests/find/test-suite-1/test.elem-match.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,26 @@ describe('test.elem-match.js', () => {
}).should.deep.equal(['2', '3']);
});

it('with null element in object array', async () => {
const db = context.db;
const docs = [
{_id: 'null-after-object', test: [{foo: 'blub'}, null]},
{_id: 'only-null', test: [null]},
{_id: 'no-match', test: [{foo: 'nope'}, null]}
];

await db.bulkDocs(docs);
const resp = await db.find({
selector: {
test: {$elemMatch: {foo: 'blub'}},
},
fields: ['_id']
});
resp.docs.map((doc) => {
return doc._id;
}).should.deep.equal(['null-after-object']);
});

it('should error for non-object query value', async () => {
const db = context.db;
try {
Expand Down