CodeIgniter MongoDB Library
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(array( 'country' => 'UK', 'like_whisky' => TRUE )) ->get('people');
The result will be an object containing matching documents.
selectGet select fields from returned documents
whereWhere section of the query
where_inWhere something is in an array of something
where_in_allWhere something is in all of an array of * something
where_not_inWhere something is not in array of something
where_gtWhere something is greater than something
where_gteWhere something is greater than or equal to something
where_ltWhere something is less than something
where_lteWhere something is less than or equal to something
where_not_equalWhere something is not equal to something
where_near` Where something is near to something (2d geospatial search)
order_byOrder the results
limitLimit the number of returned results
insertInsert a new document into a collection
incIncrements the value of a field
decDecrements the value of a field
setSets a field to a value
unset_fieldUnsets a field
addtosetAdds a value to an array if doesn't exist
pushPushes a value into an array field
popPops a value from an array field
pullRemoves an array by the value of a field
rename_fieldRename a field
updateUpdate a single document in a collection
update_allUpdate all documents in a collection
deleteDelete a single document in a collection
delete_allDelete all documents in a collection
set_indexCreates a new index
delete_indexDeletes an index
drop_dbDrops a database
switch_dbSwitch to a different database
drop_collectionDrops a collection