环境:
OS: Windows 2003
DB:2.0.8
1.下载mongodb
下载地址为http://www.mongodb.org/downloads,根据OS选择安装的版本.
我这里下载的是mongodb-win32-i386-2.0.8.zip
2.解压缩mongodb-win32-i386-2.0.8.zip
解压缩该zip包,我这里解压缩到E:\soft\mongodb-win32-i386-2.0.8,同时在该目录下创建db和log两个文件夹,这样的话该目录有如下三个文件夹.
E:\soft\mongodb-win32-i386-2.0.8\bin
E:\soft\mongodb-win32-i386-2.0.8\db
E:\soft\mongodb-win32-i386-2.0.8\log
在log文件夹下创建日志文件MongoDB.log,完全目录为E:\soft\mongodb-win32-i386-2.0.8\log\MongoDB.log
3.在PATH变量中加入E:\soft\mongodb-win32-i386-2.0.8\bin,这样就可以直接调用bin目录下的exe文件.
4.执行如下命令
mongod -dbpath "E:\soft\mongodb-win32-i386-2.0.8\db"
执行此命令即将mongodb的数据库文件创建到E:\soft\mongodb-win32-i386-2.0.8\db目录
Sun Dec 02 10:09:18 [clientcursormon] mem (MB) res:0 virt:44 mapped:
5.运行mongo.exe
C:\Documents and Settings\xueliang.huang>mongo
MongoDB shell version: 2.0.8
connecting to: test
> help
db.help() help on db methods
db.mycoll.help() help on collection methods
rs.help() help on replica set methods
help admin administrative help
help connect connecting to a db help
help keys key shortcuts
help misc misc things to know
help mr mapreduce
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
show logs show the accessible logger names
show log [name] prints out the last segment of log in memory, 'global' is default
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 further iterate
DBQuery.shellBatchSize = x set default number of items to display on shell
exit quit the mongo shell
当mongod.exe被关闭时,mongo.exe 就无法连接到数据库了,因此每次想使用mongodb数据库都要开启mongod.exe程序,所以比较麻烦,接下来我们将接下来我们将
MongoDB安装为windows服务吧
6.MongoDB安装为windows服务
创建服务
mongod --dbpath "E:\soft\mongodb-win32-i386-2.0.8\db" --logpath "E:\soft\mongodb-win32-i386-2.0.8\log\MongoDB.log" --install --serviceName "mongodb"
net start mongodb(开启服务)
net stop mongodb(关闭服务)
删除服务
mongod --dbpath "E:\soft\mongodb-win32-i386-2.0.8\db" --logpath "E:\soft\mongodb-win32-i386-2.0.8\log\MongoDB.log" --remove --serviceName "MongoDB"
mongod --dbpath "c:\mymongodb" --logpath "c:\mymongodb\logs.txt" --install --serviceName "MongoDB"
要是出现如下错误的话需要将db目录下的mongod.lock删除后再启动
>mongo
>couldn't connect to server 127.0.0.1 shell/mongo.js:84
相关文章
- ubuntu下的数据库和python存储库安装——MySQL,MongoDB,Redis
- windows xp 环境下 Oracle8i 双击安装文件无反应的解决办法
- 在windows上如何安装python web引擎jinja2
- [Anaconda] 如何在conda下使用pip安装包
- windows下cmake安装使用
- 在 Windows 下安装 COCO API(pycocotools)
- windows7下安装python3的scrapy框架
- Windows系统安装————windows7 企业版 无法安装 NET.framework4.52-4.6版本在WIN7下解决办法
- Postgresql ---plv8扩展(windows下安装过程)
- ketlle windows下的安装(最基本)