0

I have lot of Data in Mongo DB, I wanted to query based on a String value and that value contains a url

"url" : "http://some-host/api/name/service/list/1234/xyz"

I got records count when executed the below query

db.mycollection.find({url:"http://some-host/api/name/service/list/1234/xyz"}).count()

I want to get all the records which match with

some-host/api/name/service/list/

I tried using below saamples

db.mycollection.find({url:"some-host/api/name/service/list/"}).count() 

Got zero records

db.mycollection.find({url:/.*"some-host/api/name/service/list/".*/}).count()

Got error

db.mycollection.find({"url":/.*"some-host/api/name/service/list/".*/}).count()

Got error

db.mycollection.find({"url":/.*some-host/api/name/service/list/.*/}).count()

Got Error

db.mycollection.find({"url":/.*some-host//api//name//service//list//.*/}).count()

Got ...

...

Then no response

Neil Lunn
  • 148,042
  • 36
  • 346
  • 317
Sat
  • 3,520
  • 9
  • 39
  • 66

1 Answers1

1

Did you try with something like this:

db.mycollection.find({'url': {'$regex': 'sometext'}})

Please check also here

  • 1
    The question is already doing that. Using `/something/` is the same as `$regex: "something"` Read the manual page yourself to see those examples. But that is not what the question is asking. – Neil Lunn Mar 28 '19 at 10:44