0

I need to find the object whose name is "abc" from category collection in mongodb. Here is the my code

[{
    _id: 728e38e7,
    name: 'abc,def,ghi,klm,nmo',
    place: "mys"
},
{
    _id: 2788,
    name: 'djhd',
    place: "bang"
}]
zangw
  • 43,869
  • 19
  • 177
  • 214
Nithesh S D
  • 103
  • 2
  • 10

3 Answers3

0

try that

var query = { name: new RegExp('^' + abc) };
collection.find(query).toArray(function(err, items))
Özgür Ersil
  • 6,909
  • 3
  • 19
  • 29
0

Using the mongo shell you can use find().

db.collection.find({"name" : /abc/}).

From this post : How to query MongoDB with "like"?

Community
  • 1
  • 1
Peter.M
  • 13
  • 4
0

Below is the simplest method of using regex to find element based on name in mongodb :

db.collection.find({name:{$regex:"ABC",$options:"$i"}})

Here $i is used to make the search case insensitive.

pihu
  • 120
  • 10