I have a MongoDB collection that has firstName & lastName fields, I need to retrieve items that matches specific fullNames:
Is there an easy way to write a query that would check that:
firstName + " " + lastName IN ARRAY ()... ?
--- EDIT ---
The reason to concatenate is that I don't want bill jobs in the result (considering it exists) if I have [bill, steve] for firstNames & [gates, jobs] for lastname.
Thanks!
Surely you just want:
db.myCollection.find({firstName:"bill",lastName:"gates"})
or is there a specific reason to actually concatenate?
It sounds like you have the concatenated fields as your input. If that's the case, you'd be much better off splitting your input data in whatever language you're using and passing the separate fields to MongoDB.
var names = "bill gates".split();
db.myCollection.find({firstName:names[0],lastName:names[1]});
This will also let MongoDB use an index if one is defined.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With