This is a query builder inspired CodeIgniter library to integrate a MongoDB database into your application.
-
Update the config file -- mongodb.php to your /application/config folder.
-
Autoload the library or include it in one of your controllers at run time.
-
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.
select
Return select fields from returned documentswhere
Where section of the querywhere_in
Where something is in an array of somethingwhere_in_all
Where something is in all of an array of * somethingwhere_not_in
Where something is not in array of somethingwhere_gt
Where something is greater than somethingwhere_gte
Where something is greater than or equal to somethingwhere_lt
Where something is less than somethingwhere_lte
Where something is less than or equal to somethingwhere_ne
Where something is not equal to somethingwhere_near
Where something is near to something (2d geospatial search)order_by
Order the resultslimit
Limit the number of returned results
insert
Insert a new document into a collection
inc
Increments the value of a fielddec
Decrements the value of a fieldset
Sets a field to a valueunset_field
Unsets a fieldaddtoset
Adds a value to an array if doesn't existpush
Pushes a value into an array fieldpop
Pops a value from an array fieldpull
Removes an array by the value of a fieldrename_field
Rename a fieldupdate
Update a single document in a collectionupdate_all
Update all documents in a collection
delete
Delete a single document in a collectiondelete_all
Delete all documents in a collection
set_index
Creates a new indexdelete_index
Deletes an index
drop_db
Drops a databaseswitch_db
Switch to a different database
drop_collection
Drops a collection