The string you are presenting is a mongodb shell query.
This string contains mongodb shell specific datatypes, and as such is only usable inside the mongodb shell.
You can not parse or evaluate these queries in a different (javascript) enviroment, because they are not valid JSON. Hence, eval, or JSON.parse wouldn't even work, because of the specific datatypes.
If you want to serialize mongodb queries for usage in different enviroments, you could use MongoDB Extended JSON.
https://docs.mongodb.org/v3.0/reference/mongodb-extended-json/
This is standard JSON which can contain mongodb datatypes.
Your query would like this in MongoDB extended JSON.
{
"_id": {
"$oid": "536b07935c89be214c000009"
},
"date": {
"$date": "2012-12-19T06:01:17.171Z"
},
"mail": {
"$regex": "test",
"$options": "i"
}
}
If you want to parse or evaluate a string like this to pass it along to the node.js mongodb driver, you would need to use a library to deserialize this to a proper Node.js MongoDB Driver object.
You could use this library to do that:
https://www.npmjs.com/package/mongodb-extended-json
You can also use this library in your browser to build the queries. Or you could build the mongodb queries by hand.
I'm not aware of plugin / npm package that would allow you to convert mongodb shell queries to MongoDB Extended JSON automatically. You could try to convert them automatically by implementing some of the types your self ( ISODate, ObjectId ). However you will never have a full compatibility between the mongodb shell and the mongodb nodejs driver, many methods have different signatures and return types, cursors work differently, etc...
There also is this project, an alternative to the officially supported mongodb nodejs driver, which tries to mimic the shell a bit more if you really value that, but it won't help you with your specific query, you'll still need to convert it.
https://docs.mongodb.org/ecosystem/drivers/node-js/
queryin your code? Is it just a string containing the value you pasted above? How exactly does your code fail? What is the error message? You need to provide more information in order for people to help you.