简体   繁体   中英

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

{"id":1,value:"abc/123/*"}
{"id":2,value:"abc/*/lmn"}
{"id":3,value:"abc*lmn"}

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: /\*/})

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM