mongodb在Windows上安装、运行

下面主要是我在Windows上(Win7)安装、运行、安装Windows服务的笔记



1、下载



下载地址:http://www.mongodb.org/downloads



2、安装



安装非常简单,解压就行了,我解压后,放在D:/MongoDB目录下。



为了命令行的方便,可以把D:/MongoDB/bin加到系统环境变量的path中了。



3、运行

在D:/MongoDB下面创建一个数据目录 data D:/MongoDB/data

D:\>mongod --dbpath D:/mongodb/data
Wed Oct 16 14:36:57.472
Wed Oct 16 14:36:57.472 warning: 32-bit servers don't have journaling enabled by
default. Please use --journal if you want durability.
Wed Oct 16 14:36:57.472
Wed Oct 16 14:36:57.503 [initandlisten] MongoDB starting : pid=5100 port=27017 d
bpath=D:/mongodb/data 32-bit host=yanfaos3
Wed Oct 16 14:36:57.503 [initandlisten]
Wed Oct 16 14:36:57.503 [initandlisten] ** NOTE: This is a 32 bit MongoDB binary
.
Wed Oct 16 14:36:57.503 [initandlisten] **       32 bit builds are limited to le
ss than 2GB of data (or less with --journal).
Wed Oct 16 14:36:57.503 [initandlisten] **       Note that journaling defaults t
o off for 32 bit and is currently off.
Wed Oct 16 14:36:57.503 [initandlisten] **       See http://dochub.mongodb.org/c
ore/32bit
Wed Oct 16 14:36:57.503 [initandlisten]
Wed Oct 16 14:36:57.503 [initandlisten] ** NOTE: your operating system version d
oes not support the method that MongoDB
Wed Oct 16 14:36:57.503 [initandlisten] **       uses to detect impending page f
aults.
Wed Oct 16 14:36:57.503 [initandlisten] **       This may result in slower perfo
rmance for certain use cases
Wed Oct 16 14:36:57.503 [initandlisten]
Wed Oct 16 14:36:57.503 [initandlisten] db version v2.4.7-rc0
Wed Oct 16 14:36:57.503 [initandlisten] git version: 078285ab6ed605ef4714bae48d7
423c35ff96148
Wed Oct 16 14:36:57.503 [initandlisten] build info: windows sys.getwindowsversio
n(major=6, minor=0, build=6002, platform=2, service_pack='Service Pack 2') BOOST
_LIB_VERSION=1_49
Wed Oct 16 14:36:57.503 [initandlisten] allocator: system


由于是开发版,上面就有个警告,没关系,忽略它。



最后两行说明的数据库端口和Web端口,分别是27017和28017,在浏览器中打开http://localhost:27017,可以看到其相关的一些信息。


4、创建用户:
执行命令:mongo  或者 双击运行mongo.exe文件  进入
> use admin
switched to db admin   进入admin下
> db.addUser("admin","admin") 添加admin
{
        "user" : "admin",
        "readOnly" : false,
        "pwd" : "7c67ef13bbd4cae106d959320af3f704",
        "_id" : ObjectId("525e386b305c2b51bb3976a6")
}
> db.auth("admin","admin")  验证admin用户 返回1创建成功
1
> db.adduser("user1","user1")
Wed Oct 16 14:57:41.843 TypeError: Property 'adduser' of object admin is not a f
unction
> db.addUser("user1","user1")
{
        "user" : "user1",
        "readOnly" : false,
        "pwd" : "c0b6eb911ec95c050e104824c39531f3",
        "_id" : ObjectId("525e38ef305c2b51bb3976a7")
}
> use user1
switched to db user1
> db.addUser("user1","user1")
{
        "user" : "user1",
        "readOnly" : false,
        "pwd" : "c0b6eb911ec95c050e104824c39531f3",
        "_id" : ObjectId("525e3927305c2b51bb3976a8")
}
>

这个命令区分大小写,addUser 用adduser 错误


5、停止服务

  >db.shutdownServer()

猜你喜欢

转载自yuanzhen.iteye.com/blog/1958869