mongodb 安装与简单使用

windows下安装mongodb和简单使用mongodb命令
一。下载,解压文件
到官方下载合适的版本 http://www.mongodb.org/downloads
例如:http://fastdl.mongodb.org/win32/mongodb-win32-i386-1.6.5.zip
解压后放到对应的盘符下面,例如:G:\mongodb165
二。安装
1.把bin目录加入到环境变量中 G:\mongodb165\bin
2.在G:\mongodb165下建立data文件夹放数据用
3.简单启动mongodb方法:
进入到bin目录下
C:\Documents and Settings\zheng>G:
G:\>cd mongodb165/bin
G:\mongodb165\bin>mongod --dbpath G:/mongodb165/data
G:\mongodb165\bin>mongod --dbpath G:/mongodb165/data
Sun Jan 16 14:56:03 MongoDB starting : pid=860 port=27017 dbpath=G:/mongodb165/d
ata 32-bitmysql

** NOTE: when using MongoDB 32 bit, you are limited to about 2 gigabytes of datagit

**       see http://blog.mongodb.org/post/137788967/32-bit-limitationsweb

Sun Jan 16 14:56:03 db version v1.6.5, pdfile version 4.5
Sun Jan 16 14:56:03 git version: 0eb017e9b2828155a67c5612183337b89e12e291
Sun Jan 16 14:56:03 sys info: windows (5, 1, 2600, 2, 'Service Pack 3') BOOST_LI
B_VERSION=1_35
Sun Jan 16 14:56:03 [initandlisten] waiting for connections on port 27017
Sun Jan 16 14:56:03 [websvr] web admin interface listening on port 28017sql

注:必须先创建data文件夹和到bin目录下执行。mongoDB 服务端的默认链接端口是 27017mongodb

2.添加到注册表做为Windows服务启动,和mysql同样启动Windows时会自动启动服务,到bin目录下执行
G:\mongodb165\bin>mongod --logpath G:\mongodb165\logs\mongodb165.log --logappend
 --dbpath G:\mongodb165\data --directoryperdb --serviceName mongodb165 --installshell

完成后输出下面内容(360等杀毒软件会阻止,须要容许经过)
all output going to: G:\mongodb165\logs\mongodb165.log
Creating service mongodb165.
Service creation successful.
Service can be started from the command line via 'net start "mongodb165"'.数据库

G:\mongodb165\bin>windows

其中:logs\mongodb165.log日志是以追加的方式输出的,--serviceName mongodb165是服务名称
启动MongoDB:net start mongodb165
中止MongoDB:net stop mongodb165
注:添加到注册表后重启电脑在服务项里面能够看到已经启动,但服务仍然没有启动,重启服务发现给360安全卫士阻止了须要再次肯定才能启动。安全

3.mongodb的简单使用命令,到bin命令下执行mongo.exe进入管理界面,默认是进入到test账号。
G:\mongodb165\bin>mongo.exe
MongoDB shell version: 1.6.5
connecting to: test
> show dbs;
admin
local
> help;查看命令提示
        db.help()                    help on db methods
        db.mycoll.help()             help on collection methods
        rs.help()                    help on replica set methods
        help connect                 connecting to a db help
        help admin                   administrative help
        help misc                    misc things to knowapp

        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 wit h time >= 1ms         use <db_name>                set current database         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 f urther iterate         exit                         quit the mongo shell > use testdb;切换到testdb数据库,若是不存在则在插入数据后会自动建立一个,在data目录下能够看到新增了一个testdb的文件夹 switched to db testdb > db.myc.save({a:10});向collection mpc 中保存一条信息,若是不存在collection会自动建立一个 > db.myc.find();检索全部记录 { "_id" : ObjectId("4d32c9204e6100000000691e"), "a" : 10 } > show collections; myc system.indexes >exit;退出

相关文章
相关标签/搜索