当前位置:网站首页>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
边栏推荐
- The maximum number of remote desktop servers has been exceeded
- Introduction to metalama 4 Use fabric to manipulate items or namespaces
- NPDP|产品经理如何做到不会被程序员排斥?
- Qt绘制图像
- 使用Source Insight查看编辑源代码
- Dialogue with Bruce, author of PostgreSQL: "changing careers" is to better move forward
- A graphic designer's fantasy world | ones characters
- flask项目跨域拦截处理以及dbm数据库学习【包头文创网站开发】
- 梳理网络IP代理的几大用途
- Analysis of InnoDB execution process in MySQL
猜你喜欢
I changed to a programmer at the age of 31. Now I'm 34. Let me talk about my experience and some feelings
Idea setting copyright information
STM32工程移植:不同型号芯片工程之间的移植:ZE到C8
The maximum number of remote desktop servers has been exceeded
What are the forms of attack and tampering on the home page of the website
[daily question] chessboard question
Basic software testing Day2 - Case Execution
How to solve the computer system card?
电脑系统卡如何解决?
云原生KubeSphere部署Redis
随机推荐
Ad20 supplementary note 3 - shortcut key + continuous update
Buuctf Web [gxyctf2019] no dolls
How much does software testing help reduce program bugs?
NBIOT的AT指令
MySQL函数-递归函数
天梯赛赛前练习
Qt绘制文字
How to switch PHP version in Windows 2008 system
A graphic designer's fantasy world | ones characters
A graphic designer's fantasy world | ones characters
云原生KubeSphere部署Mysql
[redis series] redis learning 13. Redis often asks simple interview questions
How to prevent the website from being hacked and tampered with
基于卷积神经网络的遥感影像分类识别系统
没有空闲服务器?导入 OVF 镜像快速体验 SmartX 超融合社区版
PHP generates JSON to process Chinese
一个平面设计师的异想世界|ONES 人物
消息队列概述
Solution of asynchronous clock metastability -- multi bit signal
Resolve disagrees about version of symbol device_ create