Alternative syntax

If you are familiar with the novella of I. Asimov “Profession” I hope you understand my initiative. Often we create knowledge from nothing, and it reflects more the ambitions of some people than logic or previous experience. During many years it was Oracle, this dying giant, who trained everyone what was right or wrong. Now it’s Google who changes the order from int[ ] to [ ]int and it becomes a new language - there are too many movements but very little sense. And of course, there is MongoDB - somewhere in the middle.

I know that it’s my problems but I wish the syntax more clear, more obvious. Like:

when the field does exist and not Null:
db$ collection(:“field1”?) or db$ collection(field1 f => f?)
prompt$ db.collection.find({$and: [{“field1”: {$ne: null}}, {“field2”: {$exists: true}}]})

when the field does not exist
collection(:“field1”? == false) or the same collection(field1 f => f? == false)
db.collection.find({“field1”: {$exists: false}})

When the field does exist and is Null
collection(“field1” f => f == null)
db.collection.find({$and: [{“field1”: {$eq: null}}, {“field2”: {$exists: true}}]})

collection(field1 f => /^F./.exec(f))
db.collection.find({“field1”: {$regex: /^F.*/}})

collection(“field1” f => f contains [“some1”, “some2”])
collection(:“field1” >= [“some1”, “some2”])
db.collection.find({field1: {$all: [“some1”, "some2”]}})

collection(objectField o => o.field1 > 8 && o.field2 == “some”)
db.collection.find({objField: {$elemMatch: {“field1”: {$gt: 8}, “field2”: “some”}}})

collection(“field1” f1, “field2” f2 => f1 == “some” || f2 == 0)
collection(:“field1” == “some” || :”field2” == 0)
db.collection.find({$or: [{“field1”:{$eq: “some”}},{“field2”: {$eq: 0}}]})

find({$and: [{“status”: {$eq: “Thank you”}}, {“greeting”: {$all: [“Have”, “a”, “great”, “day”]}}]})


Hi @Denis_57508,

This seems to be bit off topic, but what you are suggesting sounds like an alternative query language, which can be supported, by implementing a transpiler.

In the case of MongoDB, we don’t try to tell you what’s right or wrong. We can teach what’s write for MongoDB and how we decided to implement our query language.
You are always free to add another abstractions layer on top of it.

MongoDB Query Language (MQL) is meant to as expressive as possible while maintaining the base B(J)SON format.

Not sure if Asimov was thinking about a database query language in his book, but I invite you to build a transpiler for your purposed syntax.


Hi @Norberto. I remove this topic. I find it also “a bit off topic”. Luckily, I don’t use the mql so often to worry about somebody’s genial ideas. But we are programmers and we firstly think about some optimization… well, I 've heard you. Thank you, @Norberto, for your comment.