MongoX 介绍
MongoX 是 Perl 语言用来操作 MongoDB 数据库的开发包。
最快速模式,连接到127.0.0.1,默认数据库 test
use MongoX host => ‘mongodb://127.0.0.1′,db => ‘test’;
按部就班的来
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;
MongoX 官网
http://search.cpan.org/dist/MongoX/
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。