Reputation: 3964
In my collection Person
I have many people named Mike.
Is there a way I can find all the people with first name Mike?
Currently I am only able to find one person at a time using the entire name.
db.getCollection('Person').find({'name':'Mike Jones'})
db.getCollection('Person').find({'name':'Mike Woo'})
db.getCollection('Person').find({'name':'Mike Smith'})
I tried doing something like:
db.getCollection('Person').find({'name':'Mike '+ *})
Very new to MongoDb thanks.
Upvotes: 2
Views: 4276
Reputation: 21682
You want something like this:
db.getCollection('Person').find({'name':/^Mike/})
Strictly speaking that is using a left anchored regular expression to look for all strings that start with "Mike", you can make it more selective if you wish.
Upvotes: 5