Abhijeet Abhijeet - 1 year ago 57
Node.js Question

Find all the documents having * in them in MongoDB

Can someone please help me with the regex for * in MongoDB.
I want to fetch all the documents having '*' in them.

like that regex (db.collection.find{value: new Regex('*')}) should return all such documents


Answer Source

You're close; you just need to add a backslash to escape the * in your regex so it won't be treated as a special character.

In the shell:

db.collection.find({value: /\*/})