当前位置:网站首页>MongoDB与SQL常用语法对应表
MongoDB与SQL常用语法对应表
2020-11-06 21:24:00 【程序猿欧文】
对于经常写SQL的同学,一开始写mongoDB的语法会十分不习惯,下表整理了常见的SQL语法,函数以及相应的MongoDB对应语法,仅供参考。
术语及概念
| 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 |
语法对应表
| 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......... |
版权声明
本文为[程序猿欧文]所创,转载请带上原文链接,感谢
https://my.oschina.net/mikeowen/blog/4556607
边栏推荐
- Flink的DataSource三部曲之一:直接API
- FastThreadLocal 是什么鬼?吊打 ThreadLocal 的存在!!
- React design pattern: in depth understanding of react & Redux principle
- Using NLP and ml to extract and construct web data
- 零基础打造一款属于自己的网页搜索引擎
- 事件监听问题
- Interpretation of Cocos creator source code: engine start and main loop
- C語言I部落格作業03
- Python基础变量类型——List浅析
- Windows 10 tensorflow (2) regression analysis of principles, deep learning framework (gradient descent method to solve regression parameters)
猜你喜欢

Who says cat can't do link tracking? Stand up for me

理解格式化原理

【自学unity2d传奇游戏开发】地图编辑器

【字节跳动 秋招岗位开放啦】Ohayoo!放学别走,我想约你做游戏!!!

DRF JWT authentication module and self customization

零基础打造一款属于自己的网页搜索引擎

零基础打造一款属于自己的网页搜索引擎

Mac installation hanlp, and win installation and use

Python基础数据类型——tuple浅析

TensorFlow中的Tensor是什么?
随机推荐
It's time for your financial report to change to a more advanced style -- financial analysis cockpit
What knowledge do Python automated testing learn?
Recommendation system based on deep learning
Simple summary of front end modularization
【自学unity2d传奇游戏开发】地图编辑器
It's easy to operate. ThreadLocal can also be used as a cache
Gather in Beijing! The countdown to openi 2020
What if the front end doesn't use spa? - Hacker News
A brief history of neural networks
If PPT is drawn like this, can the defense of work report be passed?
The difference between gbdt and XGB, and the mathematical derivation of gradient descent method and Newton method
html+vue.js 實現分頁可相容IE
Analysis of etcd core mechanism
一篇文章教会你使用Python网络爬虫下载酷狗音乐
Lane change detection
TensorFlow中的Tensor是什么?
Using NLP and ml to extract and construct web data
Introduction to quantitative investment and Trading (Python introduction to financial analysis)
Analysis of query intention recognition
零基础打造一款属于自己的网页搜索引擎