Sign In Register

How can we help you today?

Start a new topic
Answered

Mongo query using "like"

How can i use "like" in nosql windows? i used examples in the link belove. it does not work. i get json syntax error. i tried {log: { $regex: /rebuild/ } } and {log: /rebuild/ }


https://chartio.com/resources/tutorials/how-to-use-a-sql-like-statement-in-mongodb


Best Answer

Hi all, 


Just a quick amendment to Padraigs answer as it will not work in the new portal due to a more strict parser. 


The quotations around $regex should in fact be double quotes rather than single. Like so : 


{"log": {"$regex": "rebuild"}}


Best Regards, Patrick. 


Hi Ufuk,


For a query like this in the NoSQL Explorer, try this:


{"log": {'$regex': "rebuild"}}


Let me know if this works for you.


-Pádraig

Answer

Hi all, 


Just a quick amendment to Padraigs answer as it will not work in the new portal due to a more strict parser. 


The quotations around $regex should in fact be double quotes rather than single. Like so : 


{"log": {"$regex": "rebuild"}}


Best Regards, Patrick. 


1 person likes this

In my recent testing in the NoSQL explorer, the above answer failed. The solution is to use double quotes instead of single quotes around the word "$regex". So, a working example would be:


{"log": {"$regex": "rebuild"}}

Login to post a comment