当前位置:网站首页>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
边栏推荐
- nacos、ribbon和feign的簡明教程
- The dynamic thread pool in Kitty supports Nacos and Apollo multi configuration centers
- Named entity recognition in natural language processing: tanford core LP ner (1)
- C#和C/C++混合编程系列5-内存管理之GC协同
- 一路踩坑,被迫聊聊 C# 代码调试技巧和远程调试
- What are the criteria for selecting a cluster server?
- 文件过多时ls命令为什么会卡住?
- Introduction to quantitative investment and Trading (Python introduction to financial analysis)
- How to turn data into assets? Attracting data scientists
- Unity性能优化整理
猜你喜欢

StickEngine-架构11-消息队列(MessageQueue)

Even liver three all night, jvm77 high frequency interview questions detailed analysis, this?

每个大火的“线上狼人杀”平台,都离不开这个新功能

Three Python tips for reading, creating and running multiple files

小游戏云开发入门

有了这个神器,快速告别垃圾短信邮件

【ElasticSearch搜索引擎】

What are the common problems of DTU connection

Construction of encoder decoder model with keras LSTM

It's easy to operate. ThreadLocal can also be used as a cache
随机推荐
JNI-Thread中start方法的呼叫與run方法的回撥分析
Using NLP and ml to extract and construct web data
python100例項
【ElasticSearch搜索引擎】
Python filtering sensitive word records
What are manufacturing and new automation technologies?
FastThreadLocal 是什么鬼?吊打 ThreadLocal 的存在!!
Introduction to quantitative investment and Trading (Python introduction to financial analysis)
React design pattern: in depth understanding of react & Redux principle
視覺滾動[反差美]
Network security engineer Demo: the original * * is to get your computer administrator rights! [maintain]
Analysis of partial source codes of qthread
What are the criteria for selecting a cluster server?
Building and visualizing decision tree with Python
给字节的学姐讲如何准备“系统设计面试”
Pattern matching: The gestalt approach一种序列的文本相似度方法
What course of artificial intelligence? Will it replace human work?
TensorFlow中的Tensor是什么?
With the advent of tensorflow 2.0, can pytoch still shake the status of big brother?
游戏主题音乐对游戏的作用