MongoDB学习-1
最近要升级一个核算系统,需要用到MongoDB,使用前先了解一下。
1、和关系性数据库对照关系
| SQL术语/概念 | MongoDB术语/概念 | 解释/说明 |
|---|---|---|
| database | database | 数据库 |
| table | collection | 数据库表/集合 |
| row | document | 数据记录行/文档 |
| column | field | 数据字段/域 |
| index | index | 索引 |
| table joins | 表连接,MongoDB不支持 | |
| primary key | primary key | 主键,MongoDB自动将_id字段设置为主键 |
MongoDB 中可以使用的类型如下表所示:
| 类型 | 数字 | 备注 |
|---|---|---|
| Double | 1 | |
| String | 2 | |
| Object | 3 | |
| Array | 4 | |
| Binary data | 5 | |
| Undefined | 6 | 已废弃。 |
| Object id | 7 | |
| Boolean | 8 | |
| Date | 9 | |
| Null | 10 | |
| Regular Expression | 11 | |
| JavaScript | 13 | |
| Symbol | 14 | |
| JavaScript (with scope) | 15 | |
| 32-bit integer | 16 | |
| Timestamp | 17 | |
| 64-bit integer | 18 | |
| Min key | 255 | Query with -1. |
| Max key | 127 |
2、使用Navicat操作
2.1建库

2.2 建集合

保存为studentclass
2.3插入一个文档
集合上右键Add Document

单引号,双引号都支持

直接用语句插入和更新方法
db.getCollection("studentclass").insert( { Id: 3, ClassName: "班三2323" } ); db.getCollection("").update( { _id: ObjectId("5facaf87fb070000550066b6") }, { Id: 4, ClassName: "班三2323" } );
2.4查找
db.getCollection("studentclass").find()

db.getCollection("studentclass").find({ $or: [{ "ClassName": "一班" }, { "ClassName": "二班" }] })
2.5 条件查找基本上都是利用的正则表达式
db.getCollection("studentclass").find({"ClassName":"一班"}) db.getCollection("studentclass").find({ClassName:/班/}) db.getCollection("studentclass").find({ClassName:/^班/})
结果分别是



2.6 Or 语句
db.getCollection("studentclass").find({ $or: [{ "ClassName": "一班" }, { "ClassName": "二班" }] })

2.7默认就是and语句
db.getCollection("studentclass").find( { ClassName: /班$/, ClassName: /^一/, } )

当然写$and也支持
db.getCollection("studentclass").find( {$and: [{ ClassName: /班$/}, {ClassName: /^一/, }] })
其它功能使用过程中再了解
参考:https://www.runoob.com/mongodb/mongodb-tutorial.html
本博客是个人工作中记录,更深层次的问题可以提供有偿技术支持。
另外建了几个QQ技术群:
2、全栈技术群:616945527
2、硬件嵌入式开发: 75764412
3、Go语言交流群:9924600
闲置域名WWW.EXAI.CN (超级人工智能)出售。
另外建了几个QQ技术群:
2、全栈技术群:616945527
2、硬件嵌入式开发: 75764412
3、Go语言交流群:9924600
闲置域名WWW.EXAI.CN (超级人工智能)出售。

浙公网安备 33010602011771号