当前位置:网站首页>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
边栏推荐
- 使用Source Insight查看编辑源代码
- 没有空闲服务器?导入 OVF 镜像快速体验 SmartX 超融合社区版
- NPDP | how can product managers not be excluded by programmers?
- Lesson 24 analysis of classical problems
- SynchronousQueue 源码解析
- 对话PostgreSQL作者Bruce:“转行”是为了更好地前行
- 云原生KubeSphere部署Redis
- 关于使用Go语言创建WebSocket服务浅谈
- How do traditional enterprises cope with digital transformation? These books give you the answer
- 传统企业如何应对数字化转型?这些书给你答案
猜你喜欢
在 VSCode 中调试 Jest 的测试用例,VSCode调试Jest测试用例报错basedir=$(dirname “$(echo “$0“ | sed -e ‘s,\\,/,g‘)“)解决
Resolve disagrees about version of symbol device_ create
Plato farm - a game of farm metauniverse with Plato as the goal
QT interprocess communication
Qt绘制图像
Unlock openharmony technology day! The annual event is about to open!
【每日一题】棋盘问题
Fastjson 2 is coming, the performance continues to improve, and it can fight for another ten years
【csnote】ER图
ZigBee CC2530 minimum system and register configuration (1)
随机推荐
Everything can be expected in the future | one 2022 campus recruitment officially opened
BUUCTF WEB [BUUCTF 2018]Online Tool
[wechat applet] Z-index is invalid
At instruction of nbiot
Qt绘制文字
Remote sensing image classification and recognition system based on convolutional neural network
Keyword interpretation and some APIs in RT thread
Lesson 26 static member functions of classes
SSL证书退款说明
Number of nodes of complete binary tree
NPDP|产品经理如何做到不会被程序员排斥?
网站首页文件被攻击篡改的形式有哪些
Plato Farm-以柏拉图为目标的农场元宇宙游戏
Bert base Chinese Download (SMART)
mysql中 innoDB执行过程分析
SynchronousQueue 源码解析
只是不断地建构平台,不断地收拢流量,并不能够做好产业互联网
uni-app 原生APP-本地打包集成极光推送(JG-JPUSH)详细教程
Kubernets Getting started tutoriel
How to solve the computer system card?