Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there such a thing as JSON schema for MongoDB query language itself?

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?

like image 430
Vlad Avatar asked Sep 21 '18 22:09

Vlad


1 Answers

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
like image 186
Raj Nandan Sharma Avatar answered Oct 05 '22 17:10

Raj Nandan Sharma