MongoDB queries--at least in JavaScript--are structured as JSON, but it's very flexible so I am aware this wouldn't be a simple thing to do and in fact not even sure if this is possible, but was just wondering.
Is there a JSON schema to detect if a random JSON is a valid MongoDB query object?
You can use something like mongodb-language-model
How to use
var accepts = require('mongodb-language-model').accepts;
console.log(accepts('{"ns":{"$in":["foo", "bar", "baz"]}}')); // true
console.log(accepts('{"ns":{"$in":{}}}')); // false
console.log(accepts('{"ns":{"$regex": "foo"}}')); // true
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With