MongoDB快速入门

为了把明天的工作做好,我们必须把今天的工作先做好了,不要给明天的工作找麻烦。在工作面前,态度决定一切。没有不重要的工作,只有不重视工作的人。不同的态度,成就不同的人生,有什么样的态度就会产生什么样的行为,从而决定不同的结果。

对 MongoDb 文档数据库感兴趣,要安装认识下。

到官方下载 win 版 http://www.mongodb.org/display/DOCS/Downloads 目前最新稳定版是 1.2.4。解压到 f:/sofr/mongodb-win32-i386-1.2.4。

启动 mongod

 
F:\soft\mongodb-win32-i386-1.2.4>bin\mongod.exe --dbpath=f:/mongodb
Mon Mar 08 11:13:17 Mongo DB : starting : pid = 0 port = 27017 dbpath = f:/mongodb master = 0 slave
= 0 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 for more Mon Mar 08 11:13:18 db version v1.2.4, pdfile version 4.5
Mon Mar 08 11:13:18 git version: 5cf582d3d96b882c400c33e7670b811ccd47f477
Mon Mar 08 11:13:18 sys info: windows (5, 1, 2600, 2, 'Service Pack 3') BOOST_LIB_VERSION=1_35
Mon Mar 08 11:13:18 waiting for connections on port 27017

--dbpath 指定数据库的目录,默认是 /data/db,win 没有 /data/db 目录,所以直接双击 mongod 是启动不了。默认端口是 27017 linux 下我用 legacy-static 版,因为源码编译没成功。 服务器启动后,用客户端试用下,它自带有个客户端(MongoDB shell)。bin/mongo.exe
 
F:\soft\mongodb-win32-i386-1.2.4>bin\mongo.exe
MongoDB shell version: 1.2.4
url: test
connecting to: test
type "exit" to exit
type "help" for help
> use test
switched to db test
> db.foo.save({a:1})
> db.foo.find()
{ "_id" : ObjectId("4b946bc03f78000000001542"), "a" : 1 }
>

mongod.exe 后端可以看到日志。
MongoDB 客户端丰富,我用 python 试下(安装请看:http://api.mongodb.org/python/1.4%2B/installation.html)。安装 pymongo
 
easy_install pymongo
 
from pymongo import Connection
connection = Connection()
db = connection.test
for f in db.foo.find():
print "a=%s, _id=%s" % (f['a'], f['_id'])

可以看到结果。a=1.0, _id=4b946bc03f78000000001542。_id 是mongo 内部的字段。 它的像 sql 的查询比较吸引人 ……
原文:http://blog.chenlb.com/2010/03/mongodb-quick-start.html

到此这篇关于MongoDB快速入门就介绍到这了。没要腐朽没要倒退,你的眼光如婴儿般明亮,请拥抱我吧,让我的生命散发迷人的光彩,直教日月黯然。更多相关MongoDB快速入门内容请查看相关栏目,小编编辑不易,再次感谢大家的支持!

标签: MongoDB