Introduction to MongoDB Query Language in Polypheny

Welcome to the MongoDB Query Language (MQL) section of the Polypheny documentation! This section is dedicated to providing comprehensive information about utilizing MongoDB’s powerful query language within the Polypheny platform.

What is MongoDB Query Language?

MongoDB Query Language (MQL) is the rich and expressive query language used by MongoDB, a popular NoSQL database. MQL offers a potent suite of features that allow you to work with your data in versatile and powerful ways. The language is document-oriented, meaning that it operates on BSON (Binary JSON) document data structures.

Data is represented as collections of JSON-like documents. This data representation is inherently flexible, accommodating complex nested data structures with ease.

Here’s an example of a simple query:

db.collection.find({ "name" : "John Doe" })

In the MongoDB Query Language, db is a reference to the current database. In Polypheny, this referes to a namespace. The db variable is used at the beginning of every query to specify which namespace you are working with.

The current namespace is the namespace that the user has selected to work with, and all subsequent operations that use the db variable are performed within the context of that namespace.

In the example above, collection refers to the collection within that namespace, find is the operation being performed, and { "name" : "John Doe" } is the query criteria.

When to Use MongoDB Query Language

MongoDB’s query language has comprehensive capabilities that allow for complex nested queries, text search, geospatial queries, multi-document ACID transactions, and more.

In the context of Polypheny, the MongoDB Query Language is one of the supported query languages and can be used interchangeably with others depending on your use case. Whether you’re dealing with vast amounts of data, need the flexibility of a document-oriented model, or require complex querying capabilities, MQL is a valuable tool within the Polypheny ecosystem.

How to Select the Namespace

To select the namespace, you use the use command followed by the name of the namespace:

use hr

In this case, hr would be the name of the namespace you want to select. Once this command is executed, the db variable now points to hr, and any subsequent operations that you perform using db will use collections of the namespace hr.

Alternatively, there is also a Polypheny-specific extension to the MQL syntax that allows using the namespace name instead of db:


In this example, hr is the name of the namespace and employees the name of a collection.

Additionally, Polypheny provides the flexibility to omit the db. prefix entirely:

use hr

Please note that use sets the namespace for all subsequent queries, while specifying the namespace as a prefix to the collection name only affects the individual query:

use hr
employees.find() # hr namespace
public.departments.find() # public namespace
contractors.find() # hr namespace

For the sake of coherence and clarity, this documentation will predominantly show the syntax that includes the db. prefix.

© Polypheny GmbH. All Rights Reserved.