21 天学习MongoDB笔记

安装本地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术语/概念解释/说明
databasedatabase数据库
tablecollection数据库表/集合
rowdocument数据记录行/文档
columnfield数据字段/域
indexindex索引
table joins表连接,MongoDB不支持
primary keyprimary key主键,MongoDB自动将_id字段设置为主键

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Saidywin

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值