当前位置:网站首页>21 天学习MongoDB笔记
21 天学习MongoDB笔记
2022-04-23 12:39:00 【Saidywin】
安装本地MongoDB
在bin 的路径下执行 mongod --dbpath c:\data\db
执行MongoDB的代码:
> 2 + 2
4
> db
test
> db.runoob.insert({x:10})
WriteResult({ "nInserted" : 1 })
> db.runoob.find()
{ "_id" : ObjectId("625eaa86311de6f041f0ac26"), "x" : 10 }
> use mydb
switched to db mydb
> db
mydb
> show dbs
admin 0.000GB
config 0.000GB
local 0.000GB
test 0.000GB
> db.movie.insert({"name":"tutorials point"})
WriteResult({ "nInserted" : 1 })
> show dbs
admin 0.000GB
config 0.000GB
local 0.000GB
mydb 0.000GB
test 0.000GB
> use mydb
switched to db mydb
> db.createCollection("mycollection")
{ "ok" : 1 }
> show collections
movie
mycollection
> db.createCollection("mycol", { capped : true, autoIndexID : true, size : 6142800, max : 10000 } )
{
"ok" : 0,
"errmsg" : "BSON field 'create.autoIndexID' is an unknown field.",
"code" : 40415,
"codeName" : "Location40415"
}
> db.createCollection("mycol", { capped : true, autoIndexID : true, size : 6142800, max : 10000 } )
{
"ok" : 0,
"errmsg" : "BSON field 'create.autoIndexID' is an unknown field.",
"code" : 40415,
"codeName" : "Location40415"
}
> db.createCollection("mycol",{capped :true, autoIndexID:true, size : 614800\, max:10000})
uncaught exception: SyntaxError: invalid escape sequence :
@(shell):1:74
> db.createCollection("mycol",{capped :true, autoIndexID:true, size : 614800, max:10000})
{
"ok" : 0,
"errmsg" : "BSON field 'create.autoIndexID' is an unknown field.",
"code" : 40415,
"codeName" : "Location40415"
}
> use mydb
switched to db mydb
> db.createCollection("mycol", { capped : true, autoIndexID : true, size : 6142800, max : 10000 } )
{
"ok" : 0,
"errmsg" : "BSON field 'create.autoIndexID' is an unknown field.",
"code" : 40415,
"codeName" : "Location40415"
}
> db.createCollection("mycol",{capped :true, autoIndexID:true, size : 614800, max:10000})
{
"ok" : 0,
"errmsg" : "BSON field 'create.autoIndexID' is an unknown field.",
"code" : 40415,
"codeName" : "Location40415"
}
> show collections
movie
mycollection
> db.createCollection("mycol",{capped :true, size : 614800, max:10000})
{ "ok" : 1 }
> db.createCollection("mycol",{capped :true, ndexID:true, size : 614800, max:10000})
{
"ok" : 0,
"errmsg" : "BSON field 'create.ndexID' is an unknown field.",
"code" : 40415,
"codeName" : "Location40415"
}
> db.createCollection("mycol",{capped :true, ndexID:true, size : 614800, max:10000})
{
"ok" : 0,
"errmsg" : "BSON field 'create.ndexID' is an unknown field.",
"code" : 40415,
"codeName" : "Location40415"
}
> show collections
movie
mycol
mycollection
> show collections
movie
mycol
mycollection
>
MongoDB 支持如下数据类型:
- String:字符串。存储数据常用的数据类型。在 MongoDB 中,UTF-8 编码的字符串才是合法的。
- Integer:整型数值。用于存储数值。根据你所采用的服务器,可分为 32 位或 64 位。
- Boolean:布尔值。用于存储布尔值(真/假)。
- Double:双精度浮点值。用于存储浮点值。
- Min/Max keys:将一个值与 BSON(二进制的 JSON)元素的最低值和最高值相对比。
- Arrays:用于将数组或列表或多个值存储为一个键。
- Timestamp:时间戳。记录文档修改或添加的具体时间。
- Object:用于内嵌文档。
- Null:用于创建空值。
- Symbol:符号。该数据类型基本上等同于字符串类型,但不同的是,它一般用于采用特殊符号类型的语言。
- Date:日期时间。用 UNIX 时间格式来存储当前日期或时间。你可以指定自己的日期时间:创建 Date 对象,传入年月日信息。
- Object ID:对象 ID。用于创建文档的 ID。
- Binary Data:二进制数据。用于存储二进制数据。
- Code:代码类型。用于在文档中存储 JavaScript 代码。
- Regular expression:正则表达式类型。用于存储正则表达式。
| SQL术语/概念 | MongoDB术语/概念 | 解释/说明 |
|---|---|---|
| database | database | 数据库 |
| table | collection | 数据库表/集合 |
| row | document | 数据记录行/文档 |
| column | field | 数据字段/域 |
| index | index | 索引 |
| table joins | 表连接,MongoDB不支持 | |
| primary key | primary key | 主键,MongoDB自动将_id字段设置为主键 |
版权声明
本文为[Saidywin]所创,转载请带上原文链接,感谢
https://saidywin.blog.csdn.net/article/details/124282395
边栏推荐
- 一个平面设计师的异想世界|ONES 人物
- Uni app native app cloud packaging integrated Aurora push (jg-jpush) detailed tutorial
- 如何防止网站被黑客入侵篡改
- 关于使用Go语言创建WebSocket服务浅谈
- 【每日一题】棋盘问题
- 洛谷P3236 [HNOI2014]画框 题解
- Fashion cloud learning - input attribute summary
- Please help me see what this is, mysql5 5. Thanks
- Object.keys后key值数组乱序的问题
- [redis series] redis learning 13. Redis often asks simple interview questions
猜你喜欢

4.DRF 权限&访问频率&过滤&排序

STM32工程移植:不同型号芯片工程之间的移植:ZE到C8

S2-062 远程命令执行漏洞复现(cve-2021-31805)

Pagoda panel command line help tutorial (including resetting password)

Fashion cloud learning - input attribute summary

在 VSCode 中调试 Jest 的测试用例,VSCode调试Jest测试用例报错basedir=$(dirname “$(echo “$0“ | sed -e ‘s,\\,/,g‘)“)解决

电脑系统卡如何解决?
![[daily question] chessboard question](/img/70/54a924d07c935965e54b96d9b07278.png)
[daily question] chessboard question

Qt绘制图像
![[redis series] redis learning 13. Redis often asks simple interview questions](/img/4c/2440af6daa26a0ca6cb64f32bf138e.png)
[redis series] redis learning 13. Redis often asks simple interview questions
随机推荐
flask项目跨域拦截处理以及dbm数据库学习【包头文创网站开发】
Resolve disagrees about version of symbol device_ create
【unity笔记】L4Unity中的基础光照
电脑系统卡如何解决?
C set Logo Icon and shortcut icon
Solution of asynchronous clock metastability -- multi bit signal
QT one process runs another
MySQL function - recursive function
Idea setting copyright information
Zigbee之CC2530最小系统及寄存器配置(1)
QT draw image
SQLserver怎么插入或更新当天的星期数,bit而不是文本
mysql中 innoDB执行过程分析
为什么hash%length==hash&(length-1)的前提是 length 是 2 的 n 次方
Recommended programming AIDS: picture tool snipaste
[daily question] chessboard question
Basic software testing Day2 - Case Execution
[redis series] redis learning 13. Redis often asks simple interview questions
MySQL函数-递归函数
Luogu p5540 [balkanoi2011] timeismoney | minimum product spanning tree problem solution