Get the App
SLTechnology News&Howtos  ›  Database  › 

How to support SQL-like query in MongoDB

Shulou Source: shulou.com Published: 2022-05-31 21:13:30 09月21日 Update

This article introduces you how to support SQL query in MongoDB, the content is very detailed, interested friends can use it for reference, hope to be helpful to you.

The data model of relational database is simple, and it is a single-layer two-dimensional table with distinct rows and columns; so the computing language (SQL) to describe it is relatively simple; while in MongoDB, there are multi-layer nested structures and attribute fields appear arbitrarily. It is not easy just to describe which field information is selected clearly. Coupled with further grouping, aggregation, condition and sorting operations, the complexity increases exponentially, which is the fundamental reason why it has been difficult to calculate based on MongoDB database for many years.

If you use the aggregator SPL language, which fully supports collection operations, it is easier to deal with this multi-layer nested data structure, just look at the code:

A2=mongo_shell (A1, "computer.find ()"). Fetch () 3=A2.new (_ id:ID,income.array (). Sum (): INCOME,output.array (). Sum (): OUTPUT)

This is basically exactly the same as the ideal SQL:

SELECT _ id:ID,income.array () .sum (): INCOME,output.array () .sum (): OUTPUT FROM computer

The MongoDB script that makes the same query has the following code size:

On how to support SQL-like queries in MongoDB to share here, I hope the above content can be of some help to you, you can learn more knowledge. If you think the article is good, you can share it for more people to see.

Tags: Data support query code content multi-tier field database more structure language help good complex clear difficult identical information interest single layer Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Linux Shulou Technology MariaDB MySQL Apple