当前位置:网站首页>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
边栏推荐
- Qt绘制文字
- Worder font page font comparison table
- 解锁OpenHarmony技术日!年度盛会,即将揭幕!
- 【微信小程序】z-index失效
- How do programmers finalize nucleic acid statistics with 130 lines of code
- SSL证书退款说明
- Flash project cross domain interception and DBM database learning [Baotou cultural and creative website development]
- 如何防止网站被黑客入侵篡改
- NBIOT的AT指令
- I changed to a programmer at the age of 31. Now I'm 34. Let me talk about my experience and some feelings
猜你喜欢
![[csnote] ER diagram](/img/97/82e8c2183fcafda50950a953ca0955.png)
[csnote] ER diagram

Basic software testing Day2 - Case Execution

Zero trust in network information security

Metalama简介4.使用Fabric操作项目或命名空间

解锁OpenHarmony技术日!年度盛会,即将揭幕!

XinChaCha Trust SSL Organization Validated

A graphic designer's fantasy world | ones characters

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

Bert base Chinese Download (SMART)

How do programmers finalize nucleic acid statistics with 130 lines of code
随机推荐
Use source insight to view and edit source code
实现一个盒子在父盒子中水平垂直居中的几种“姿势”
Keyword interpretation and some APIs in RT thread
甲辰篇 創世紀《「內元宇宙」聯載》
Ad20 supplementary note 3 - shortcut key + continuous update
Remote sensing image classification and recognition system based on convolutional neural network
On using go language to create websocket service
传统企业如何应对数字化转型?这些书给你答案
Introduction to kubernetes
BUUCTF WEB [BUUCTF 2018]Online Tool
Analysis of InnoDB execution process in MySQL
STM32工程移植:不同型号芯片工程之间的移植:ZE到C8
Object.keys后key值数组乱序的问题
Buuctf Web [bjdctf2020] zjctf, but so
[unity note] basic lighting in l4unity
BUUCTF WEB [GXYCTF2019]禁止套娃
Resolve disagrees about version of symbol device_ create
Fashion cloud learning - input attribute summary
Lesson 23 temporary objects
QT one process runs another