This is an active record inspired CodeIgniter library to integrate a MongoDB database into your application.
- Add the file Mongo_db.php to your /application/libraries folder.
- Add the file mongodb.php to your /application/config folder.
- Update the config file.
You can now autoload the library or include it in one of your controllers at run time.
You can interact with the database using many of the active record functions that CodeIgniter provides.
$this->mongo_db
->where_gte('age', 18)
->where_in('country', array(
'England',
'Scotland',
'Wales',
'Ireland'
))
->where(array(
'likes_whisky' => TRUE
))
->get('people');
The result will be an object containing matching documents.
selectGet select fields from returned documentswhereWhere section of the querywhere_inWhere something is in an array of somethingwhere_in_allWhere something is in all of an array of * somethingwhere_not_inWhere something is not in array of somethingwhere_gtWhere something is greater than somethingwhere_gteWhere something is greater than or equal to somethingwhere_ltWhere something is less than somethingwhere_lteWhere something is less than or equal to somethingwhere_not_equalWhere something is not equal to something- `where_near`` Where something is near to something (2d geospatial search)
order_byOrder the resultslimitLimit the number of returned results
insertInsert a new document into a collection
incIncrements the value of a fielddecDecrements the value of a fieldsetSets a field to a valueunset_fieldUnsets a fieldaddtosetAdds a value to an array if doesn't existpushPushes a value into an array fieldpopPops a value from an array fieldpullRemoves an array by the value of a fieldrename_fieldRename a fieldupdateUpdate a single document in a collectionupdate_allUpdate all documents in a collection
deleteDelete a single document in a collectiondelete_allDelete all documents in a collection
set_indexCreates a new indexdelete_indexDeletes an index
drop_dbDrops a databaseswitch_dbSwitch to a different database
drop_collectionDrops a collection