From fd8a538516d52bccde1fae9f8722fa7868dd5a07 Mon Sep 17 00:00:00 2001 From: Louis Chatriot Date: Sun, 17 Jan 2016 11:36:55 -0800 Subject: [PATCH] Update README.md --- README.md | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 7a5fc73..7ffa5fd 100755 --- a/README.md +++ b/README.md @@ -271,10 +271,17 @@ db.find({ planet: { $regex: /ar/, $nin: ['Jupiter', 'Earth'] } }, function (err, ``` #### Array fields -When a field in a document is an array, NeDB first tries to see if there is an array-specific comparison function (for now there is only `$size`) being used -and tries it first. If there isn't, the query is treated as a query on every element and there is a match if at least one element matches. +When a field in a document is an array, NeDB first tries to see if the query value is an array to perform an exact match, then whether there is an array-specific comparison function (for now there is only `$size`) being used. If not, the query is treated as a query on every element and there is a match if at least one element matches. ```javascript +// Exact match +db.find({ satellites: ['Phobos', 'Deimos'] }, function (err, docs) { + // docs contains Mars +}) +db.find({ satellites: ['Deimos', 'Phobos'] }, function (err, docs) { + // docs is empty +}) + // Using an array-specific comparison function // Note: you can't use nested comparison functions, e.g. { $size: { $lt: 5 } } will throw an error db.find({ satellites: { $size: 2 } }, function (err, docs) {