Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to support SQL-like query in MongoDB

2025-03-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)05/31 Report--

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.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 204

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report