本内容主要是windows的版本
1、下载与安装
说一个快速启动的方案:创建两个.bat文件,内容如下:
(1)启动数据库:mongod --dbpath E:\MongoDATA\journal [E:\MongoDATA\journal 代表你要吧数据库存入的地方]
(2)连接数据库:mongo 127.0.0.1:27017/admin [以admin用户登录到mongoDB]
附录:关于MongoDB-help 的详细解释:
2、附上我自己测试过的一些命令吧
--显示数据库列表
> show dbs
admin 0.000GB
config 0.000GB
local 0.000GB
psersons 0.000GB
--使用数据库
> use persons
switched to db persons
--显示文件列表
> show collections
persons
psersons
--查询某个文件的数据
> db.psersons.find()
{ "_id" : ObjectId("5b4059af6cd605c650d11507"), "name" : "extjs" }
--给psersons插入数据
> db.psersons.insert({age:"18"})
WriteResult({ "nInserted" : 1 })
> db.psersons.find()
{ "_id" : ObjectId("5b4059af6cd605c650d11507"), "name" : "extjs" }
{ "_id" : ObjectId("5b4064c76cd605c650d11508"), "age" : "18" }
-------查询第一条数据
> db.psersons.findOne()
{ "_id" : ObjectId("5b4059af6cd605c650d11507"), "name" : "extjs" }
-------更新数据
> db.psersons.update({name:"extjs"},{$set:{name:"extjs4.1"}})
WriteResult({ "nMatched" : 1, "nUpserted" : 0, "nModified" : 1 })
-------定义变量,然后输出变量P
> var p = db.psersons.findOne()
> p
{ "_id" : ObjectId("5b4059af6cd605c650d11507"), "name" : "extjs4.1" }
-------使用变量更新数据
> db.update.update(p,{name:"extjsupdatep4.1"})
WriteResult({ "nMatched" : 0, "nUpserted" : 0, "nModified" : 0 })
> p
{ "_id" : ObjectId("5b4059af6cd605c650d11507"), "name" : "extjs4.1" }
-------始用$Set 和不始用的区别: 如果不始用,就会替换掉之前的,如果使用了,key不同的话,会在后面新增一个
> db.psersons.update(p,{name:"extjsupdatep4.1"})
WriteResult({ "nMatched" : 1, "nUpserted" : 0, "nModified" : 1 })
> var p = db.psersons.findOne()
> p
{ "_id" : ObjectId("5b4059af6cd605c650d11507"), "name" : "extjsupdatep4.1" }
> db.psersons.findOne()
{ "_id" : ObjectId("5b4059af6cd605c650d11507"), "name" : "extjsupdatep4.1" }
> db.psersons.update(p,{age:"12"})
WriteResult({ "nMatched" : 1, "nUpserted" : 0, "nModified" : 1 })
> var p = db.psersons.findOne()
> p
{ "_id" : ObjectId("5b4059af6cd605c650d11507"), "age" : "12" }
> db.psersons.update(p,{$set:{name:"extjs"}})
WriteResult({ "nMatched" : 1, "nUpserted" : 0, "nModified" : 1 })
> var p = db.psersons.findOne()
> p
{
"_id" : ObjectId("5b4059af6cd605c650d11507"),
"age" : "12",
"name" : "extjs"
}
> db.psersons.find()
{ "_id" : ObjectId("5b4059af6cd605c650d11507"), "age" : "12", "name" : "extjs" }
{ "_id" : ObjectId("5b4064c76cd605c650d11508"), "age" : "18" }
>
----------删除数据
> db.psersons.remove({age:"18"})
WriteResult({ "nRemoved" : 1 })
> db.psersons.find()
{ "_id" : ObjectId("5b4059af6cd605c650d11507"), "age" : "12", "name" : "extjs" }
上面是我这次大概使用到的东西。
主要是要看得懂mongo -help 的说明,后面的命令都是从这里来的。