S
S
Sahnen2018-08-01 02:01:29
MongoDB
Sahnen, 2018-08-01 02:01:29

How to set the field value to "any" in the search?

For example:

Users.find( { name: 'Иван', age: __ANY_VALUE__ } ).limit(20);

From the request, Monga needs to find all users named Ivan, of any age.
Those. how to set this same __ANY_VALUE__ so that the request is similar to ? Users.find( { name: 'Иван' } ).limit(20);

Answer the question

In order to leave comments, you need to log in

1 answer(s)
U
Urukhayy, 2018-08-01
@Sahnen

If you have query parameters supplied to find as an object, then as an option, before calling find , you can remove this field:

var query = {
    name: 'John',
    age: '18'
}

delete query['age']
Users.find( query ).limit(20);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question