简体   繁体   English

如何使用Codeigniter选择不同的mongodb数据库

[英]How to select distinct mongodb database using Codeigniter

I am very new to using mongodb via Codeigniter. 我是通过Codeigniter使用mongodb的新手。 I have noticed some active records for Mongodb is very similar to the sql for instance 我注意到Mongodb的一些活动记录与实例的sql非常相似

$this->db->get('mytable');
$this->mongo_db->get('mytable');

However I ran into a problem where the distinct does not work: 但是我遇到了一个问题,其中独特的东西不起作用:

$this->mongo_db->distinct('name');
$this->mongo_db->get('mytable');

Been searching around for this but couldn't find anything, is there a way for this? 一直在寻找这个,但找不到任何东西,有没有办法解决?

Many thanks 非常感谢

I working with this library for CodeIgniter ( https://github.com/alexbilbie/codeigniter-mongodb-library ), and there exists the method: switch_db($db_name); 我正在使用此库用于CodeIgniter( https://github.com/alexbilbie/codeigniter-mongodb-library ),并且存在方法:switch_db($ db_name);

Then with the get you can choose witch collection (in MongoDB tables are collections), like you did in your example: 然后使用get可以选择巫婆集合(在MongoDB中的表是集合),就像您在示例中所做的那样:

$this->mongo_db->get('collection_name'); $ this-> mongo_db-> get('collection_name');

You can use : 您可以使用 :

$this->mongo_db->distinct('collection', 'field_name');

It will help you to find distict value from collection. 这将帮助您从集合中找到不同的价值。 make sure you have installed mongo_db library. 确保已安装mongo_db库。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM