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.
select
Get 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_not_equal
Where something is not equal to something- `where_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