数据库

 首页 > 数据库 > MongoDB > Windows系统安装与使用MongoDB数据库的方法

Windows系统安装与使用MongoDB数据库的方法

分享到:
【字体:
导读:
         摘要:windows下安装mongodb和简单使用mongodb命令一。下载,解压文件到官方下载合适的版本http://www.mongodb.org/downloads例如:http://fastdl.mongodb.org/win32/mongodb-win32-i386-1.6.5.zip解压后放到对应的盘符下面,例如...

Windows系统安装与使用MongoDB数据库的方法
一。下载,解压文件
到官方下载合适的版本 http://www.mongodb.org/downloads
例如:http://fastdl.mongodb.org/win32/mongodb-win32-i386-1.6.5.zip
解压后放到对应的盘符下面,例如:G:mongodb165

二。安装
1.把bin目录加入到环境变量中 G:mongodb165bin
2.在G:mongodb165下创建data文件夹放数据用
3.简单启动mongodb方法:
进入到bin目录下
C:Documents and Settingszheng>G:
G:>cd mongodb165/bin
G:mongodb165bin>mongod --dbpath G:/mongodb165/data
G:mongodb165bin>mongod --dbpath G:/mongodb165/data
Sun Jan 16 14:56:03 MongoDB starting : pid=860 port=27017 dbpath=G:/mongodb165/d
ata 32-bit
** NOTE: when using MongoDB 32 bit, you are limited to about 2 gigabytes of data
**       see http://blog.mongodb.org/post/137788967/32-bit-limitations
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 28017
注:必须先建立data文件夹和到bin目录下执行。mongoDB 服务端的默认连接端口是 27017

2.添加到注册表作为Windows服务启动,和mysql一样启动Windows时会自动启动服务,到bin目录下执行
G:mongodb165bin>mongod --logpath G:mongodb165logsmongodb165.log --logappend
 --dbpath G:mongodb165data --directoryperdb --serviceName mongodb165 --install
完成后输出下面内容(360等杀毒软件会阻止,需要允许通过)
all output going to: G:mongodb165logsmongodb165.log
Creating service mongodb165.
Service creation successful.
Service can be started from the command line via 'net start "mongodb165"'.
G:mongodb165bin>
其中:logsmongodb165.log日志是以追加的方式输出的,--serviceName mongodb165是服务名称
启动MongoDB:net start mongodb165
停止MongoDB:net stop mongodb165
注:添加到注册表后重启电脑在服务项里面可以看到已经启动,但服务仍然没有启动,重启服务发现给360安全卫士阻止了需要再次确定才能启动。

3.mongodb的简单使用命令,到bin命令下执行mongo.exe进入管理界面,默认是进入到test帐号。
G:mongodb165bin>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 know
        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                 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;退出
Windows系统安装与使用MongoDB数据库的方法
分享到:
MongoDB数据库在Linux和Windows中的安装...
MongoDB数据库在Linux和Windows中的安装配置方法 MongoDB是一个高性能,开源,无模式的文档型数据库,是当前NoSql数据库中比较热门的一种。它在许多场景下可用于替代传统的关系型数据库或键/值存储方式。Mongo使用C++开发。Mongo的官方网站地址是:http://www.mongodb.org/,读者可以在此获得更详细的信息。  ...
MongoDB数据库安装与使用方法
MongoDB数据库安装与使用方法 1. MongoDB的安装,我使用了Linux的编译版本,解压后就可以使用。 (哪位有从源码编译的教程,还请指教!) 1.1 启动 /usr/local/mongodb/bin/mongod --quiet --dbpath /data/mongo --bind_ip 127.0.0.1 --fork --logpath /dev/null --pidfilepath=/usr/local/mongodb/mongo.pid & 1...
  •         php迷,一个php技术的分享社区,专属您自己的技术摘抄本、收藏夹。
  • 在这里……