当前位置:网站首页>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
边栏推荐
- 前端工程师需要懂的前端面试题(c s s方面)总结(二)
- vue任意关系组件通信与跨组件监听状态 vue-communication
- Brief introduction and advantages and disadvantages of deepwalk model
- 事件监听问题
- Uncle Bob: the software architecture is similar to a house. Object oriented is the structure of the house, and the water pipe is functional programming
- 给字节的学姐讲如何准备“系统设计面试”
- 前端未來趨勢之原生API:Web Components
- NLP model Bert: from introduction to mastery (2)
- Advanced Vue component pattern (3)
- Windows 10 tensorflow (2) regression analysis of principles, deep learning framework (gradient descent method to solve regression parameters)
猜你喜欢
华为Mate 40 系列搭载HMS有什么亮点?
事务的隔离级别与所带来的问题
FastThreadLocal 是什么鬼?吊打 ThreadLocal 的存在!!
Interface pressure test: installation, use and instruction of siege pressure test
Elasticsearch数据库 | Elasticsearch-7.5.0应用搭建实战
有了这个神器,快速告别垃圾短信邮件
游戏主题音乐对游戏的作用
Music generation through deep neural network
How to customize sorting for pandas dataframe
[Xinge education] poor learning host computer series -- building step 7 Simulation Environment
随机推荐
StickEngine-架构12-通信协议
Brief introduction and advantages and disadvantages of deepwalk model
TensorFlow中的Tensor是什么?
【應用程式見解 Application Insights】Application Insights 使用 Application Maps 構建請求鏈路檢視
Jmeter——ForEach Controller&Loop Controller
Brief introduction of TF flags
一篇文章带你了解HTML表格及其主要属性介绍
Pollard's Rho algorithm
C語言I部落格作業03
Behind the first lane level navigation in the industry
The importance of big data application is reflected in all aspects
Python download module to accelerate the implementation of recording
游戏开发中的新手引导与事件管理系统
Python Jieba segmentation (stuttering segmentation), extracting words, loading words, modifying word frequency, defining thesaurus
Solve the problem of database insert data garbled in PL / SQL developer
Electron application uses electronic builder and electronic updater to realize automatic update
Basic usage of GDB debugging
What are manufacturing and new automation technologies?
React design pattern: in depth understanding of react & Redux principle
一篇文章带你了解CSS3 背景知识