简体   繁体   中英

How to select distinct mongodb database using Codeigniter

I am very new to using mongodb via Codeigniter. I have noticed some active records for Mongodb is very similar to the sql for instance

$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);

Then with the get you can choose witch collection (in MongoDB tables are collections), like you did in your example:

$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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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