MongoX

News:

Download

latest: http://github.com/nightsailer/mongo-x/tarball/v0.002

安装

$> sudo cpanm MongoX

源码

  • Github http://github.com/nightsailer/mongo-x/

快速使用

# 最快速模式,连接到127.0.0.1,默认数据库 test
use MongoX ( host => ‘mongodb://127.0.0.1′,db => ‘test’ , utf8=>0 );

# 按部就班的来
use MongoX;
#添加一个默认的connection
add_connection host => ’127.0.0.1′;
#启用默认的connection
use_connection;
#切换到数据库 test
use_db ‘test’;

#添加另一个数据库连接,连接id为remote2
add_connection host => ’192.168.1.1′,id => ‘remote2′;

#切换到remote2 连接
use_connection ‘remote2′;

#返回当前数据库中 foo这个collection
my $foo = get_collection ‘foo’;

#将 ‘foo’ 设置为默认的collection
use_collection ‘foo’;

#context_collection是默认collection
say ‘total rows:’,context_collection->count();

my $id = context_collection->insert({ name => ‘Pan’, home => ‘Beijing’ });
# context_db是当前默认的数据库,即 remote2连接中的foo
my $gridfs = context_db->get_gridfs;

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>