当前位置:网站首页>Common syntax corresponding table of mongodb and SQL
Common syntax corresponding table of mongodb and SQL
2020-11-06 21:24:00 【Irving the procedural ape】
For writing often SQL Classmate , Write at the beginning mongoDB I'm not used to it , The following table sorts out the common SQL grammar , Function and corresponding MongoDB Correspondence grammar , For reference only .
Terms and concepts
| SQL |
MongoDB |
| database | database |
| table | collection |
| row | document |
| column | field |
| index | index |
| table joins | $lookup |
| primary key | primary key |
| SELECT INTO NEW_TABLE | $out |
| MERGE INTO TABLE | $merge(mongodb > 4.2) |
| UNION ALL | $unionWith (mongodb > 4.4) |
| transactions | transactions |
Grammar correspondence table
| SQL | MongoDB |
CREATE TABLE people ( id MEDIUMINT NOT NULL AUTO_INCREMENT, user_id Varchar(30), age Number, status char(1), PRIMARY KEY (id) ) |
db.createCollection("people")
db.people.insertOne( { user_id: "abc123", age: 55, status: "A" } ) |
| ALTER TABLE people ADD join_date DATETIME |
db.people.updateMany( { }, { $set: { join_date: new Date() } } ) |
| ALTER TABLE people DROP COLUMN join_date |
db.people.updateMany( { }, { $unset: { "join_date": "" } } ) |
CREATE INDEX idx_user_id_asc ON people(user_id) |
db.people.createIndex( { user_id: 1 } ) |
| CREATE INDEX idx_user_id_asc_age_desc ON people(user_id, age DESC) |
db.people.createIndex( { user_id: 1, age: -1 } ) |
| DROP TABLE people | db.people.drop() |
INSERT INTO people(user_id, age,status) VALUES ("bcd001",45,"A") |
db.people.insertOne( { user_id: "bcd001", age: 45, status: "A" } ) |
| SELECT * FROM people | db.people.find() |
SELECT id, user_id, status FROM people |
db.people.find( { }, &n......... |
版权声明
本文为[Irving the procedural ape]所创,转载请带上原文链接,感谢
边栏推荐
- 解决 WPF 绑定集合后数据变动界面却不更新的问题
- The native API of the future trend of the front end: web components
- jenkins安装部署过程简记
- Stickinengine architecture 11 message queue
- 嘉宾专访|2020 PostgreSQL亚洲大会阿里云数据库专场:曾文旌
- [forward] how to view UserData in Lua
- Why is the LS command stuck when there are too many files?
- 谷歌浏览器实现视频播放加速功能
- An article will introduce you to HTML tables and their main attributes
- 预留电池接口,内置充放电电路及电量计,迅为助力轻松搞定手持应用
猜你喜欢

Outsourcing is really difficult. As an outsourcer, I can't help sighing.

2020-08-14:数据任务的执行引擎用的哪些?

An article will take you to understand CSS3 fillet knowledge

Python basic variable type -- list analysis

Git rebase is in trouble. What to do? Waiting line

Novice guidance and event management system in game development

An article will take you to understand SVG gradient knowledge

谷歌浏览器实现视频播放加速功能

面试官: ShardingSphere 学一下吧

An article takes you to understand CSS3 picture border
随机推荐
Tron smart wallet PHP development kit [zero TRX collection]
打工人好物——磨炼钢铁意志就要这样高效的电脑
How does cglib implement multiple agents?
The native API of the future trend of the front end: web components
Call analysis of start method in JNI thread and callback analysis of run method
CloudQuery V1.2.0 版本发布
Swagger 3.0 brushes the screen every day. Does it really smell good?
An article takes you to understand CSS pagination examples
image operating system windows cannot be used on this platform
2020-08-30:裸写算法:二叉树两个节点的最近公共祖先。
Building a new generation cloud native data lake with iceberg on kubernetes
What is the meaning of sector sealing of filecoin mining machine since the main network of filecoin was put online
Why is the LS command stuck when there are too many files?
2020-09-04:函数调用约定了解么?
Using iceberg on kubernetes to create a new generation of cloud original data Lake
Kubernetes and OAM to build a unified, standardized application management platform knowledge! (Internet disk link attached)
Isn't data product just a report? absolutely wrong! There are university questions in this category
How much disk space does a new empty file take?
What the hell is fastthreadlocal? The existence of ThreadLocal!!
Zero basis to build a web search engine of its own