- 浏览: 3941 次
- 性别:
- 来自: 北京
最新评论
MongoDB:1. Database
authenticatijavascriptmongodbdatabase服务器
摘要:mongo是MongoDB自带的交互式Javascript shell,用来对Mongod进行操作和管理的交互式环境。 使用 ./mongo --help 可查看相关连接参数。 $ ./mongo --help MongoDB shell version: 1.5.3 usage: ./mongo [options] [db address] [fi
mongo是MongoDB自带的交互式Javascript shell,用来对Mongod进行操作和管理的交互式环境。
使用 "./mongo --help" 可查看相关连接参数。
$ ./mongo --help
MongoDB shell version: 1.5.3
usage: ./mongo [options] [db address] [file names (ending in .js)]
db address can be:
foo foo database on local machine
192.169.0.5/foo foo database on 192.168.0.5 machine
192.169.0.5:9999/foo foo database on 192.168.0.5 machine on port 9999
options:
--shell run the shell after executing files
--nodb don't connect to mongod on startup - no 'db address'
arg expected
--quiet be less chatty
--port arg port to connect to
--host arg server to connect to
--eval arg evaluate javascript
-u [ --username ] arg username for authentication
-p [ --password ] arg password for authentication
-h [ --help ] show this usage information
--version show version information
--ipv6 enable IPv6 support (disabled by default)
file names: a list of files to run. files have to end in .js and will exit after unless --shell is specified
相关命令很多,要习惯使用 "help"。
$ ./mongo
MongoDB shell version: 1.5.3
connecting to: test
type "help" for help
> help
help admin misc shell commands
show dbs show database names
show collections show collections in current database
show users show users in current database
show profile show most recent system.profile entries with time >= 1ms
use <db name> set current database to <db name>
db.help() help on DB methods
db.foo.help() help on collection methods
db.foo.find() list objects in collection foo
db.foo.find( { a : 1 } ) list objects in foo where a == 1
it result of the last line evaluated; use to further iterate
exit quit the mongo shell
(1) MongoDB 会自动创建数据库(db)和集合(collection),无需显式执行。
$ ./mongo
MongoDB shell version: 1.5.3
connecting to: test
type "help" for help
> show dbs // 查看当前数据库列表
admin
local
> use blog // 切换到工作数据库
switched to db blog
> db // 当前数据库
blog
> for (var i = 0; i < 10; i++) db.users.save({name : "user" + i, age : i}) // 插入数据
> show dbs // 数据库 blog 被创建
admin
blog
local
> show collections // 列表 users 被创建
system.indexes
users
> db.copyDatabase("blog", "blog2") // 复制数据库
{ "ok" : true }
> show dbs // 数据库 blog2 被创建
admin
blog
blog2
local
> use blog2 // 切换到 blog2
switched to db blog2
> show collections // 查看集合列表
system.indexes
users
> db.users.find() // 查看被复制的数据
{ "_id" : ObjectId("4c33f8fcecf2b9320ac2981a"), "name" : "user0", "age" : 0 }
{ "_id" : ObjectId("4c33f8fcecf2b9320ac2981b"), "name" : "user1", "age" : 1 }
{ "_id" : ObjectId("4c33f8fcecf2b9320ac2981c"), "name" : "user2", "age" : 2 }
{ "_id" : ObjectId("4c33f8fcecf2b9320ac2981d"), "name" : "user3", "age" : 3 }
{ "_id" : ObjectId("4c33f8fcecf2b9320ac2981e"), "name" : "user4", "age" : 4 }
{ "_id" : ObjectId("4c33f8fcecf2b9320ac2981f"), "name" : "user5", "age" : 5 }
{ "_id" : ObjectId("4c33f8fcecf2b9320ac29820"), "name" : "user6", "age" : 6 }
{ "_id" : ObjectId("4c33f8fcecf2b9320ac29821"), "name" : "user7", "age" : 7 }
{ "_id" : ObjectId("4c33f8fcecf2b9320ac29822"), "name" : "user8", "age" : 8 }
{ "_id" : ObjectId("4c33f8fcecf2b9320ac29823"), "name" : "user9", "age" : 9 }
> db.dropDatabase() // 删除数据库 blog2
{ "dropped" : "blog2", "ok" : true }
> show dbs // 确认数据库删除成功
admin
blog
local
> use blog // 切换回 blog
switched to db blog
> db.users.drop() // 删除集合 users
true
> show collections // 确认集合被删除
system.indexes
> exit
bye
(2) 还可以在多台服务器之间复制数据库。
server64$ ./mongo
MongoDB shell version: 1.5.3
connecting to: test
type "help" for help
> use blog
switched to db blog
> for (var i = 0; i < 10; i++) db.users.save({name : "user" + i, age : i})
> use news
switched to db news
> for (var i = 0; i < 10; i++) db.articles.save({title : "title" + i})
> show dbs
admin
blog
local
news
> exit
bye
准备好源数据库后,我们开始在复制。
server32:$ ./mongo
MongoDB shell version: 1.5.4
connecting to: test
> db.copyDatabase("blog", "blog", "192.168.1.202") // 从源服务器复制 blog 数据库
{ "ok" : true }
> show dbs // 复制成功
admin
blog
local
> use blog
switched to db blog
> show collections
system.indexes
users
> db.users.find()
{ "_id" : ObjectId("4c33fadb15b7f104d297e644"), "name" : "user0", "age" : 0 }
{ "_id" : ObjectId("4c33fadb15b7f104d297e645"), "name" : "user1", "age" : 1 }
{ "_id" : ObjectId("4c33fadb15b7f104d297e646"), "name" : "user2", "age" : 2 }
{ "_id" : ObjectId("4c33fadb15b7f104d297e647"), "name" : "user3", "age" : 3 }
{ "_id" : ObjectId("4c33fadb15b7f104d297e648"), "name" : "user4", "age" : 4 }
{ "_id" : ObjectId("4c33fadb15b7f104d297e649"), "name" : "user5", "age" : 5 }
{ "_id" : ObjectId("4c33fadb15b7f104d297e64a"), "name" : "user6", "age" : 6 }
{ "_id" : ObjectId("4c33fadb15b7f104d297e64b"), "name" : "user7", "age" : 7 }
{ "_id" : ObjectId("4c33fadb15b7f104d297e64c"), "name" : "user8", "age" : 8 }
{ "_id" : ObjectId("4c33fadb15b7f104d297e64d"), "name" : "user9", "age" : 9 }
> use news
switched to db news
> db.cloneDatabase("192.168.1.202") // 从源服务器克隆当前数据库(news)
{ "ok" : true }
> show dbs
admin
blog
local
news
> show collections
articles
system.indexes
> db.articles.find()
{ "_id" : ObjectId("4c33fb6215b7f104d297e64e"), "title" : "title0" }
{ "_id" : ObjectId("4c33fb6215b7f104d297e64f"), "title" : "title1" }
{ "_id" : ObjectId("4c33fb6215b7f104d297e650"), "title" : "title2" }
{ "_id" : ObjectId("4c33fb6215b7f104d297e651"), "title" : "title3" }
{ "_id" : ObjectId("4c33fb6215b7f104d297e652"), "title" : "title4" }
{ "_id" : ObjectId("4c33fb6215b7f104d297e653"), "title" : "title5" }
{ "_id" : ObjectId("4c33fb6215b7f104d297e654"), "title" : "title6" }
{ "_id" : ObjectId("4c33fb6215b7f104d297e655"), "title" : "title7" }
{ "_id" : ObjectId("4c33fb6215b7f104d297e656"), "title" : "title8" }
{ "_id" : ObjectId("4c33fb6215b7f104d297e657"), "title" : "title9" }
> exit
bye
(3) 当我们使用 use 切换到某个数据库时,变量 db 表示当前数据库。还可以用 getSisterDB() 函数获取其他数据库的引用。
> use admin
switched to db admin
> db
admin
> blog = db.getSisterDB("blog")
blog
> blog.users.insert({name : "abc"})
> blog.users.find({name : "abc"})
{ "_id" : ObjectId("4c3419b0492aa4cfbec11895"), "name" : "abc" }
(4) 调用 fsync 命令,可以强制将内存中缓存数据写回数据库文件。如果不想等待,可添加 async 参数异步执行。
> use admin
switched to db admin
> db.runCommand({fsync : 1})
{ "numFiles" : 6, "ok" : true }
> db.runCommand({fsync : 1, async : true})
{ "numFiles" : 6, "ok" : true }
(5) 某些时候需要锁定系统,阻塞所有写操作,诸如备份、整理数据库等等。锁定时读操作不受影响。
$ ./mongo
MongoDB shell version: 1.5.3
connecting to: test
type "help" for help
> use blog
switched to db blog
> admin = db.getSisterDB("admin")
admin
> admin.runCommand({fsync : 1, lock : 1}) // 锁定
{
"info" : "now locked against writes, use db.$cmd.sys.unlock.findOne() to unlock",
"ok" : true
}
> db.users.find() // 读操作正常
{ "_id" : ObjectId("4c33fadb15b7f104d297e644"), "name" : "user0", "age" : 0 }
{ "_id" : ObjectId("4c33fadb15b7f104d297e645"), "name" : "user1", "age" : 1 }
{ "_id" : ObjectId("4c33fadb15b7f104d297e646"), "name" : "user2", "age" : 2 }
{ "_id" : ObjectId("4c33fadb15b7f104d297e647"), "name" : "user3", "age" : 3 }
{ "_id" : ObjectId("4c33fadb15b7f104d297e648"), "name" : "user4", "age" : 4 }
{ "_id" : ObjectId("4c33fadb15b7f104d297e649"), "name" : "user5", "age" : 5 }
{ "_id" : ObjectId("4c33fadb15b7f104d297e64a"), "name" : "user6", "age" : 6 }
{ "_id" : ObjectId("4c33fadb15b7f104d297e64b"), "name" : "user7", "age" : 7 }
{ "_id" : ObjectId("4c33fadb15b7f104d297e64c"), "name" : "user8", "age" : 8 }
{ "_id" : ObjectId("4c33fadb15b7f104d297e64d"), "name" : "user9", "age" : 9 }
> db.users.save({name : "xyz" }) // 写操作被阻塞,等待 ...
另开启一个终端,解除锁定。
> use admin
switched to db admin
> db.$cmd.sys.unlock.findOne()
{ "ok" : 1, "info" : "unlock requested" }
解除后,前一终端被阻塞的写操作正确返回。
(6) 调用 validate() 验证集合是否存在错误。
> db.users.validate()
{
"ns" : "blog.users",
"result" : "
validate
firstExtent:0:2600 ns:blog.users
lastExtent:0:23d00 ns:blog.users
# extents:2
datasize?:4640 nrecords?:116 lastExtentSize:9216
padding:1
first extent:
loc:0:2600 xnext:0:23d00 xprev:null
nsdiag:blog.users
size:2304 firstRecord:0:26b0 lastRecord:0:2ec8
116 objects found, nobj:116
6496 bytes data w/headers
4640 bytes data wout/headers
deletedList: 0000000010000000000
deleted: n: 1 size: 4672
nIndexes:1
blog.users.$_id_ keys:116
",
"ok" : true,
"valid" : true,
"lastExtentSize" : 9216
}
authenticatijavascriptmongodbdatabase服务器
摘要:mongo是MongoDB自带的交互式Javascript shell,用来对Mongod进行操作和管理的交互式环境。 使用 ./mongo --help 可查看相关连接参数。 $ ./mongo --help MongoDB shell version: 1.5.3 usage: ./mongo [options] [db address] [fi
mongo是MongoDB自带的交互式Javascript shell,用来对Mongod进行操作和管理的交互式环境。
使用 "./mongo --help" 可查看相关连接参数。
$ ./mongo --help
MongoDB shell version: 1.5.3
usage: ./mongo [options] [db address] [file names (ending in .js)]
db address can be:
foo foo database on local machine
192.169.0.5/foo foo database on 192.168.0.5 machine
192.169.0.5:9999/foo foo database on 192.168.0.5 machine on port 9999
options:
--shell run the shell after executing files
--nodb don't connect to mongod on startup - no 'db address'
arg expected
--quiet be less chatty
--port arg port to connect to
--host arg server to connect to
--eval arg evaluate javascript
-u [ --username ] arg username for authentication
-p [ --password ] arg password for authentication
-h [ --help ] show this usage information
--version show version information
--ipv6 enable IPv6 support (disabled by default)
file names: a list of files to run. files have to end in .js and will exit after unless --shell is specified
相关命令很多,要习惯使用 "help"。
$ ./mongo
MongoDB shell version: 1.5.3
connecting to: test
type "help" for help
> help
help admin misc shell commands
show dbs show database names
show collections show collections in current database
show users show users in current database
show profile show most recent system.profile entries with time >= 1ms
use <db name> set current database to <db name>
db.help() help on DB methods
db.foo.help() help on collection methods
db.foo.find() list objects in collection foo
db.foo.find( { a : 1 } ) list objects in foo where a == 1
it result of the last line evaluated; use to further iterate
exit quit the mongo shell
(1) MongoDB 会自动创建数据库(db)和集合(collection),无需显式执行。
$ ./mongo
MongoDB shell version: 1.5.3
connecting to: test
type "help" for help
> show dbs // 查看当前数据库列表
admin
local
> use blog // 切换到工作数据库
switched to db blog
> db // 当前数据库
blog
> for (var i = 0; i < 10; i++) db.users.save({name : "user" + i, age : i}) // 插入数据
> show dbs // 数据库 blog 被创建
admin
blog
local
> show collections // 列表 users 被创建
system.indexes
users
> db.copyDatabase("blog", "blog2") // 复制数据库
{ "ok" : true }
> show dbs // 数据库 blog2 被创建
admin
blog
blog2
local
> use blog2 // 切换到 blog2
switched to db blog2
> show collections // 查看集合列表
system.indexes
users
> db.users.find() // 查看被复制的数据
{ "_id" : ObjectId("4c33f8fcecf2b9320ac2981a"), "name" : "user0", "age" : 0 }
{ "_id" : ObjectId("4c33f8fcecf2b9320ac2981b"), "name" : "user1", "age" : 1 }
{ "_id" : ObjectId("4c33f8fcecf2b9320ac2981c"), "name" : "user2", "age" : 2 }
{ "_id" : ObjectId("4c33f8fcecf2b9320ac2981d"), "name" : "user3", "age" : 3 }
{ "_id" : ObjectId("4c33f8fcecf2b9320ac2981e"), "name" : "user4", "age" : 4 }
{ "_id" : ObjectId("4c33f8fcecf2b9320ac2981f"), "name" : "user5", "age" : 5 }
{ "_id" : ObjectId("4c33f8fcecf2b9320ac29820"), "name" : "user6", "age" : 6 }
{ "_id" : ObjectId("4c33f8fcecf2b9320ac29821"), "name" : "user7", "age" : 7 }
{ "_id" : ObjectId("4c33f8fcecf2b9320ac29822"), "name" : "user8", "age" : 8 }
{ "_id" : ObjectId("4c33f8fcecf2b9320ac29823"), "name" : "user9", "age" : 9 }
> db.dropDatabase() // 删除数据库 blog2
{ "dropped" : "blog2", "ok" : true }
> show dbs // 确认数据库删除成功
admin
blog
local
> use blog // 切换回 blog
switched to db blog
> db.users.drop() // 删除集合 users
true
> show collections // 确认集合被删除
system.indexes
> exit
bye
(2) 还可以在多台服务器之间复制数据库。
server64$ ./mongo
MongoDB shell version: 1.5.3
connecting to: test
type "help" for help
> use blog
switched to db blog
> for (var i = 0; i < 10; i++) db.users.save({name : "user" + i, age : i})
> use news
switched to db news
> for (var i = 0; i < 10; i++) db.articles.save({title : "title" + i})
> show dbs
admin
blog
local
news
> exit
bye
准备好源数据库后,我们开始在复制。
server32:$ ./mongo
MongoDB shell version: 1.5.4
connecting to: test
> db.copyDatabase("blog", "blog", "192.168.1.202") // 从源服务器复制 blog 数据库
{ "ok" : true }
> show dbs // 复制成功
admin
blog
local
> use blog
switched to db blog
> show collections
system.indexes
users
> db.users.find()
{ "_id" : ObjectId("4c33fadb15b7f104d297e644"), "name" : "user0", "age" : 0 }
{ "_id" : ObjectId("4c33fadb15b7f104d297e645"), "name" : "user1", "age" : 1 }
{ "_id" : ObjectId("4c33fadb15b7f104d297e646"), "name" : "user2", "age" : 2 }
{ "_id" : ObjectId("4c33fadb15b7f104d297e647"), "name" : "user3", "age" : 3 }
{ "_id" : ObjectId("4c33fadb15b7f104d297e648"), "name" : "user4", "age" : 4 }
{ "_id" : ObjectId("4c33fadb15b7f104d297e649"), "name" : "user5", "age" : 5 }
{ "_id" : ObjectId("4c33fadb15b7f104d297e64a"), "name" : "user6", "age" : 6 }
{ "_id" : ObjectId("4c33fadb15b7f104d297e64b"), "name" : "user7", "age" : 7 }
{ "_id" : ObjectId("4c33fadb15b7f104d297e64c"), "name" : "user8", "age" : 8 }
{ "_id" : ObjectId("4c33fadb15b7f104d297e64d"), "name" : "user9", "age" : 9 }
> use news
switched to db news
> db.cloneDatabase("192.168.1.202") // 从源服务器克隆当前数据库(news)
{ "ok" : true }
> show dbs
admin
blog
local
news
> show collections
articles
system.indexes
> db.articles.find()
{ "_id" : ObjectId("4c33fb6215b7f104d297e64e"), "title" : "title0" }
{ "_id" : ObjectId("4c33fb6215b7f104d297e64f"), "title" : "title1" }
{ "_id" : ObjectId("4c33fb6215b7f104d297e650"), "title" : "title2" }
{ "_id" : ObjectId("4c33fb6215b7f104d297e651"), "title" : "title3" }
{ "_id" : ObjectId("4c33fb6215b7f104d297e652"), "title" : "title4" }
{ "_id" : ObjectId("4c33fb6215b7f104d297e653"), "title" : "title5" }
{ "_id" : ObjectId("4c33fb6215b7f104d297e654"), "title" : "title6" }
{ "_id" : ObjectId("4c33fb6215b7f104d297e655"), "title" : "title7" }
{ "_id" : ObjectId("4c33fb6215b7f104d297e656"), "title" : "title8" }
{ "_id" : ObjectId("4c33fb6215b7f104d297e657"), "title" : "title9" }
> exit
bye
(3) 当我们使用 use 切换到某个数据库时,变量 db 表示当前数据库。还可以用 getSisterDB() 函数获取其他数据库的引用。
> use admin
switched to db admin
> db
admin
> blog = db.getSisterDB("blog")
blog
> blog.users.insert({name : "abc"})
> blog.users.find({name : "abc"})
{ "_id" : ObjectId("4c3419b0492aa4cfbec11895"), "name" : "abc" }
(4) 调用 fsync 命令,可以强制将内存中缓存数据写回数据库文件。如果不想等待,可添加 async 参数异步执行。
> use admin
switched to db admin
> db.runCommand({fsync : 1})
{ "numFiles" : 6, "ok" : true }
> db.runCommand({fsync : 1, async : true})
{ "numFiles" : 6, "ok" : true }
(5) 某些时候需要锁定系统,阻塞所有写操作,诸如备份、整理数据库等等。锁定时读操作不受影响。
$ ./mongo
MongoDB shell version: 1.5.3
connecting to: test
type "help" for help
> use blog
switched to db blog
> admin = db.getSisterDB("admin")
admin
> admin.runCommand({fsync : 1, lock : 1}) // 锁定
{
"info" : "now locked against writes, use db.$cmd.sys.unlock.findOne() to unlock",
"ok" : true
}
> db.users.find() // 读操作正常
{ "_id" : ObjectId("4c33fadb15b7f104d297e644"), "name" : "user0", "age" : 0 }
{ "_id" : ObjectId("4c33fadb15b7f104d297e645"), "name" : "user1", "age" : 1 }
{ "_id" : ObjectId("4c33fadb15b7f104d297e646"), "name" : "user2", "age" : 2 }
{ "_id" : ObjectId("4c33fadb15b7f104d297e647"), "name" : "user3", "age" : 3 }
{ "_id" : ObjectId("4c33fadb15b7f104d297e648"), "name" : "user4", "age" : 4 }
{ "_id" : ObjectId("4c33fadb15b7f104d297e649"), "name" : "user5", "age" : 5 }
{ "_id" : ObjectId("4c33fadb15b7f104d297e64a"), "name" : "user6", "age" : 6 }
{ "_id" : ObjectId("4c33fadb15b7f104d297e64b"), "name" : "user7", "age" : 7 }
{ "_id" : ObjectId("4c33fadb15b7f104d297e64c"), "name" : "user8", "age" : 8 }
{ "_id" : ObjectId("4c33fadb15b7f104d297e64d"), "name" : "user9", "age" : 9 }
> db.users.save({name : "xyz" }) // 写操作被阻塞,等待 ...
另开启一个终端,解除锁定。
> use admin
switched to db admin
> db.$cmd.sys.unlock.findOne()
{ "ok" : 1, "info" : "unlock requested" }
解除后,前一终端被阻塞的写操作正确返回。
(6) 调用 validate() 验证集合是否存在错误。
> db.users.validate()
{
"ns" : "blog.users",
"result" : "
validate
firstExtent:0:2600 ns:blog.users
lastExtent:0:23d00 ns:blog.users
# extents:2
datasize?:4640 nrecords?:116 lastExtentSize:9216
padding:1
first extent:
loc:0:2600 xnext:0:23d00 xprev:null
nsdiag:blog.users
size:2304 firstRecord:0:26b0 lastRecord:0:2ec8
116 objects found, nobj:116
6496 bytes data w/headers
4640 bytes data wout/headers
deletedList: 0000000010000000000
deleted: n: 1 size: 4672
nIndexes:1
blog.users.$_id_ keys:116
",
"ok" : true,
"valid" : true,
"lastExtentSize" : 9216
}
发表评论
-
MongoDB:5. Admin
2014-06-18 11:16 516MongoDB:5. Admin 浏览器interfac ... -
MongoDB:4. Index
2014-06-18 11:14 502MongoDB:4. Index优化python文档inde ... -
MongoDB:3. Schema Design
2014-06-18 11:11 363MongoDB:3. Schema Design 数据库正则 ... -
MongoDB:2. Basic Usage
2014-06-18 11:10 472MongoDB:2. Basic Usage 数据库basi ...
相关推荐
var collection = database.GetCollection("myCollection"); // 插入文档 collection.InsertOneAsync(new BsonDocument { {"name", "John"} }); // 查询文档 var filter = Builders<BsonDocument>.Filter.Eq("name...
1. **水平扩展能力**:MongoDB的设计允许它很容易地进行水平扩展。通过将数据分布在多个服务器上,可以显著提高系统的处理能力和数据容量。 2. **索引机制**:MongoDB提供了类似于关系型数据库的索引机制,用户可以...
1. 连接MongoDB:输入`mongo.exe`命令,连接到本地MongoDB服务。 2. 创建数据库:使用`use <database_name>`命令,如`use testdb`,创建一个名为"testdb"的数据库。 3. 插入数据:在选定的数据库中,使用`db....
1. 下载地址:用户可以从MongoDB官方网站下载MongoDB Atlas的客户端软件。 2. 注册登录:用户需要注册一个MongoDB账户,然后登录到MongoDB Atlas网站。 3. Connect to Atlas:用户可以连接到MongoDB Atlas云数据库,...
例如,`new MongoDB\Driver\Manager`用于创建管理器对象,然后可以使用`selectDatabase()`方法选择要操作的数据库。 3. 集合操作:集合是MongoDB中的数据存储单元,类似于关系数据库中的表。扩展提供了对集合的CRUD...
- **数据库**: MongoDB中的数据库(database)用于组织相关的集合。 - **获取和启动MongoDB**: 指导用户如何下载安装MongoDB,并进行基本配置。 - **MongoDB Shell**: 提供了一个命令行界面,用于执行MongoDB的CRUD...
您通过databaseName提供的数据库应该已经存在,并且需要运行两个ALTER DATABASE命令: ALTER DATABASE DATETIMEFORMAT yyyy - MM - dd ' T ' HH:mm: ss . SSSALTER DATABASE TIMEZONE UTC` ` `The sink will ...
MongoDB is a powerful, flexible, and scalable generalpurpose database. It combines the ability to scale out with features such as secondary indexes, range queries, sorting, aggregations, and ...
在MongoDB中,核心概念包括数据库(Database)、集合(Collection)和文档(Document)。数据库是存储数据的地方,类似于关系型数据库中的数据库;集合是数据库中的逻辑组,类似于表,但不需预定义结构;文档则是...
- **数据库(Database)**:数据库是MongoDB中的数据存储单元。它可以包含多个集合。 - **集合(Collection)**:集合类似于关系型数据库中的表,用于存储文档。一个数据库可以包含多个集合。 - **文档(Document)**:...
MongoCollection<Document> collection = database.getCollection("sms_info"); // 插入文档 Document doc = new Document("name", "John").append("age", 30); collection.insertOne(doc); // 查询文档 for...
1. 下载 MongoDB 的安装包,例如mongodb-win32-i386-2.6.6.zip。 2. 解压缩安装包到 E:\mongodb 目录下。 3. 配置环境变量 path,加上“;E:\mongodb\bin;”。 4. 在 E:\mongodb 下建立文件夹 data\db,形成目录“E:\...
mongod --logpath D:\mongodb\log\log1.log --logappend --dbpath D:\mongodb\data --directoryperdb --serviceName mongodb --install ``` 完成安装后,可以通过`net start "mongodb"`来启动服务。 #### 四、...
资源分类:Python库 所属语言:Python 资源全名:jaraco.mongodb-3.9.3.tar.gz 资源来源:官方 安装方法:https://lanzao.blog.csdn.net/article/details/101784059
- `db.collectionName.save({key1: value1, key2: value2})`,如果_id已存在,则更新数据,否则插入新文档。 3. **修改数据**: - `db.collectionName.update(query, updateDocument, upsert, multi)`,其中query...
**步骤1:导入公钥** 首先需要导入MongoDB包管理系统使用的公钥,确保后续的安装过程安全可靠。 ```bash wget -qO - https://www.mongodb.org/static/pgp/server-6.0.asc | sudo apt-key add - ``` **步骤2:创建...
This book is intended for database professionals, software developers, and architects who have some previous experience with MongoDB and now want to shift their focus to the concepts of data modeling....