nedb icon indicating copy to clipboard operation
nedb copied to clipboard

Support for $all operator for array fields

Open TomV opened this issue 9 years ago • 2 comments

Given the dataset:

{"_id": 1, "name": "Joe", "tags": ['sailing', 'chess', 'whisky', 'cheese', 'football']}
{"_id": 2, "name": "Jane", "tags": ['wine', 'cheese', 'ballet', 'opera']}
{"_id": 3, "name": "Mary", "tags": ['sailing', 'wine', 'cheese', 'hiking']}
{"_id": 4, "name": "Mike", "tags": ['hiking', 'chess', 'beer', 'wine', 'skiing', 'football']}

To find all the documents/people who have an interest in ALL of these 'sailing', 'wine', 'cheese', I can do this in mongo:

var query = db.find(
{  "tags": {
     $all: ['sailing', 'wine', 'cheese']
    } 
});

But nedb does not support {$all: [array]}, so the alternative is to use $and, and repeat the field to check:

var query = db.find( { 
  $and: 
      [
        {"tags": 'sailing'},
        {"tags": 'wine'},
        {"tags": 'cheese'}
      ]
});

It would be more concise if the mogodb "$all" operator were supported. Louis - can you nudge me in the right direction to make write a patch to support this?

TomV avatar May 13 '15 22:05 TomV

I need the same feature.. Is their any solution ?

@TomV what about your solution performance ?

popod avatar Oct 31 '16 21:10 popod

Hi, any news on this one? This feature would be really nice, especially as MongoDb has it as well :)

JulianLang avatar Jan 31 '21 20:01 JulianLang