node.js - Mongoose use array in find().where() -


i have array of strings want use parameter finding documents in mongodb.

basically want is

// using query builder person.   find().   where('name.last').equals('ghost' || 'etc' || 'etc').... 

but instead of using bunch of or statements, want pass array of strings.

is possible?

just use .in method, taking $in operator in play:

person.   find().   where('name.last').in(['ghost', 'foo', 'bar']) 

quoting the mongodb docs:

the $in operator selects documents value of field equals value in specified array.


Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -