Reputation: 471
I want to write an $in
query if column path starts with "/v1/user/1" or "/v1/user/2" then I want to select that particular document.
The sample document is as below:
{
"_id" : ObjectId("5f8872b486aa9e79d71d9809"),
"method" : "get",
"path" : "/v1/user/1/details/"
}
I tried to create a query but getting syntax error because of "/"
db.user.find({ "path": { $in: [ /^/v1/user/1/ , /^/v1/user/2/ ] } })
Could some one please help how to write the query.
Upvotes: 0
Views: 1016
Reputation: 1615
Your query was almost correct. You just missed to escape the /
. Try below query.
db.user.find({ "path": { $in: [ /^\/v1\/user\/1/ , /^\/v1\/user\/2/ ] } })
Upvotes: 4