Giter VIP home page Giter VIP logo

codeigniter-mongo-library's People

Contributors

bryant1410 avatar intekhabrizvi avatar zeevgl avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

codeigniter-mongo-library's Issues

Updating key of an object

Which function can i use if i want to update a field inside an object ?

For Example:
{
"day": "2017-01-27",
"clicks": {
"50,100": 1,
"100,150": 3
}
}
This is a document..how can i increment the value of "50,100" key ?

Any kind of help is appreciated.

affected row

i need to count of the affected document after update in mongo db , is there any option to find out

explain()

Fatal error: Call to a member function explain() on a non-object in app\libraries\Mongo_db.php on line 1763

Error in aggregate Function

HI @ALL,

i got the error
`An uncaught Exception was encountered
Type: MongoDB\Driver\Exception\CommandException

Message: The 'cursor' option is required, except for aggregate with the explain argument

Filename: C:\inetpub\wwwroot\fileshark\application\libraries\Mongo_db.php

Line Number: 1776`

I did found the same issues as solved here but it dossent help me.

I do not know if I am using the function correctly.

My Option
$opn = array(['$group' => ['accessRules' => array('$first' => array('Identity')), ]], ['cursor' => ['batchSize' => 0,]] );

Library cannot work with PHP7 or "mongodb" PECL driver?

If you load the PECL driver "mongodb" you get the error:

The MongoDB PECL extension has not been installed or enabled

The error is very deceptive because it really should say "The Mongo PECL" ext isn't found and not the "MongoDB" extension. This is because this git repo only works with the PECL library called "mongo". The "mongo" library is not only deprecated but has a PHP requirement of:

pecl/mongo requires PHP (version >= 5.3.0, version <= 5.99.99)

If it is true that the there is no way to use the current "mongodb" driver and we have to downgrade our PHP to 5.x for this to work, can this be added in big bold letters in the readme? I think a lot of us are wasting a lot of time with this library because instructions are unclear.

Also, it would be courteous to change this line:

show_error("The MongoDB PECL extension has not been installed or enabled", 500);

To say this:

show_error("The Mongo PECL extension has not been installed or enabled", 500);

about update record

don't know how to update a record where some record is equal to xxx

also, want to ask about upsert function, can this library work for upsert function?

how to get the last id ? And aggregate error

how to get the last insert id ?
and I tried aggregate error like this appeared "Aggregation operation failed: localhost: 27017: The 'cursor' option is required, except for aggregate with the explain argument"
code
$res = $this->mongo_db->aggregate(
'player',
array(
'$lookup' => array(
'from' => 'player_detail',
'localField' => 'player_detail_id',
'foreignField' => '_id',
'as' => 'detail',
)
),
array('cursor' => array('batchSize' => 0))
);

Error in add index on collection

Hello
Why do i cannot add index on collection?
The error is Index could not be created to MongoDB Collection because no keys were specified
My code is $this->mongo_db->add_index('omid','time');
When i use $this->mongo_db->add_index('omid',array('time' => "ASC"));
again have error Message: Undefined variable: command
Thank you guys

Order_by with special characters

Hello,
I noticed that using the library native order_by function, the special characters order got wrong. The result was something like this:

  • Adamantina
  • Altair
  • Baurú
  • Jaú
  • São Carlos
  • Vinhedo
  • Águas da Prata
  • Óleo

But the correct order is:

  • Adamantina
  • Águas da Prata
  • Altair
  • Baurú
  • Jaú
  • Óleo
  • São Carlos
  • Vinhedo

So I've used the following solution for this (PHP 5.3+):

// Old database request
$myArray = $this->mongo_db->order_by(array('city' => 'asc'))->get('cities');

// New database request
$myArray = $this->mongo_db->get('cities');

// Remove order_by function and use this instead
usort($myArray, function($o, $n) {
    $ot = iconv('UTF-8', 'ASCII//TRANSLIT', $o['city']);
    $nt = iconv('UTF-8', 'ASCII//TRANSLIT', $n['city']);
    return strcmp($ot, $nt);
});

Well, just sharing a solution for a bug that I believe should be fixed. Cheers!

$elemMatch support

we are trying to run below query. do we have $elemMatch support in this library. or can we create/build custom/native query which can be directly passed to mongodb.

var Query = {
userId: {
$ne: id
},
users: {
$elemMatch: {
$eq: id
}
}
};

Join two collection

how can i join two collection?

Check my collections bellow :
First collection, called books, having the following data:

{
"isbn": "12",
"title": "Some cool book",
"author": "John Doe"
}
{
"isbn": "13",
"title": "Another awesome book",
"author": "Jane Roe"
}

And the second collection, called books_selling_data, having the following data:

{
"_id": ObjectId("56e31bcf76cdf52e541d9d26"),
"isbn": "12",
"copies_sold": 12500
}
{
"_id": ObjectId("56e31ce076cdf52e541d9d28"),
"isbn": "13",
"copies_sold": 720050
}

Update of data into MongoDB failed: -.-.-.-:27017: unrecognized write concern field: journal

All settings
$config['mongo_db']['live']['no_auth'] = FALSE;
$config['mongo_db']['live']['hostname'] = '-.-.-.-';
$config['mongo_db']['live']['port'] = '27017';
$config['mongo_db']['live']['username'] = '-----';
$config['mongo_db']['live']['password'] = '----';
$config['mongo_db']['live']['database'] = 'admin';
$config['mongo_db']['live']['db_debug'] = TRUE;
$config['mongo_db']['live']['return_as'] = 'array';
$config['mongo_db']['live']['write_concerns'] = (int)1;
$config['mongo_db']['live']['journal'] = TRUE;
$config['mongo_db']['live']['read_preference'] = NULL;
$config['mongo_db']['live']['read_preference_tags'] = NULL;

count the number of field in a set of documents

I got a problem when I use db.collection.aggregate in MongoDB.

I have a data structure like:

`$ops = array(

array(
    '$group' => array(
        "_id" => null,
        "total" => array( '$sum' => '$aulas' )
    )
)

);

$dados['consulta1'] =  $this->mongo_db->aggregate('matriz_curricular', $ops);`

An Error Was Encountered

Aggregation operation failed: localhost:27017: The 'cursor' option is required, unless 'explain' is true

Finding Prev / Next document not working!

function create_next_link($id) { $id = new MongoId($id); $this->mongo_db->where(array('status' => 1)); $this->mongo_db->where_gt('_id',$id); $this->mongo_db->order_by(array('_id'=>'DESC')); $this->mongo_db->limit(1); return $this->mongo_db->get('property'); }

Above code not returning correct document! Do you have any ideas ?

method push error

I write code with method push and i receive Error warning
Code:
$this->mongo_db->where(array('mid'=>'1349218578462396'))->push('data', array('message' =>'test123'))->update('message');
Error:
Update of data into MongoDB failed: localhost:27017: The field 'data' must be an array but is of type Object in document

aggregate cursor error

Hi @intekhabrizvi I'm using your mongodb library but I have a problem, I get this error when I query on mongoDB. I would be very happy if you help

$ops = array(
array('$lookup'=> array('from'=>'balances', 'localField'=> '_id', 'foreignField'=>"OrderID", 'as'=> "balances"))
);
$orders = $this->mongo_db->aggregate('orders', $ops);
print_r($orders);

method like invalid in php7

method like error, and MongoRegex is invalid in php7.
then,change
$regex = "/$value/$flags"; $this->wheres[$field] = new MongoRegex($regex);
to
$this->wheres[$field] = [ '$regex' => '.*'. $value . '.*', '$options' => $flags, ];
and it works well.

aggregate ($lookup) support. (aka Join)

Hi there, this is an awesome library. But I think it would be much more awesome with mongos join methods. https://www.mongodb.com/blog/post/joins-and-other-aggregation-enhancements-coming-in-mongodb-3-2-part-1-of-3-introduction

Sample schema.

db.left.find()
{ "_id" : ObjectId("56b0ea87e64ac61fa9b36b2b"), "name" : "Rod", "ref" : 1 }
{ "_id" : ObjectId("56b0ea87e64ac61fa9b36b2c"), "name" : "Jane", "ref" : 1 }
{ "_id" : ObjectId("56b0ea87e64ac61fa9b36b2d"), "name" : "Freddy", "ref" : 2 }

db.right.find()
{ "_id" : 1, "rightData" : "One" }
{ "_id" : 2, "rightData" : "Two" }

db.left.aggregate(
[{
    $lookup:
    {
        from: "right",
        localField: "ref",
        foreignField: "_id", 
        as: "stuffFromRight" 
    }
}])
{ "_id" : ObjectId("56b0ea87e64ac61fa9b36b2b"), "name" : "Rod", "ref" : 1, "stuffFromRight" : [ { "_id" : 1, "rightData" : "One" } ] }
{ "_id" : ObjectId("56b0ea87e64ac61fa9b36b2c"), "name" : "Jane", "ref" : 1, "stuffFromRight" : [ { "_id" : 1, "rightData" : "One" } ] }
{ "_id" : ObjectId("56b0ea87e64ac61fa9b36b2d"), "name" : "Freddy", "ref" : 2, "stuffFromRight" : [ { "_id" : 2, "rightData" : "Two" } ] } 

How to use aggrigate?

I am using aggrigate function like:

->aggregate ('$concat: [ "FirstName", " - ", "LastName" ]')

I know this is stupid way, please guide me.

transactions

we need transactions in this great library. tlike sql server
$this->db->trans_begin();
$this->db->trans_commit();
$this->db->trans_rollback();
thank you

mongo_db->command()

Just a suggestion..

  1. Undefined $query were use instead of $command
  2. Should command() be on MongoDb Object instead if MongoCollection?
    -- I'm running mapreduce, this changes seem to work ok.
- 1540: public function command($collection, $command = array())
+ 1540: public function command($collection = FALSE, $command = array())
- 1542: if (empty($collection))
- 1543: {
- 1544:     show_error("No Mongo collection specified to run command", 500);
- 1545: }
- 1554: $returns = $this->db->{$collection}->command($query);
+ 1554: if (!empty($collection))
+ 0: {
+ 0:     $returns = $this->db->{$collection}->command($command);
+ 0: }
+ 0: else
+ 0: {
+ 0:     $returns = $this->db->command($command);
+ 0: }

Working with ObjectID

How to find documents with ObjectID? When I use following data request:
$this->mongo_db->where(array('_id'=>'ObjectId("570e938b407729003100002a")'))->get('school');
It gives me null response, but data exist with that object id, I tried it on bash.

Does library need to be updated to use MongoDB\Driver\Manager?

Getting "The MongoDB PECL extension has not been installed or enabled", despite phpinfo reporting the extension being installed:

mongodb version: 1.1.7

If I try to initialize MongoClient I get:

Fatal error: Class 'MongoClient' not found 

But if I use the latest class syntax:

new MongoDB\Driver\Manager("mongodb://localhost:27017");

It works.

Is the library outdated?

Unable to run it

I followed the process from this link
but got an error while running a test code

The MongoDB PECL extension has not been installed or enabled

class Test_mongo extends CI_Controller { public function getData(){ $result = $this->mongo_db->select('blood_request'); echo $result; } }

What could be the issue?

Aggregation result exceeds maximum document size

I am getting this error message while getting large records
Message: localhost:27017: aggregation result exceeds maximum document size (16MB) php

After that I have added allowDiskUse and maxTimeMS but its still same error
$collection->aggregate($pipeline, array("allowDiskUse" => true, "maxTimeMS" => 1800000));

last query

how can i reach last query in mongodb ?

no command function

please add command function as follow:

        /**
         * Command.
         * 
         * Runs a MongoDB command (such as GeoNear). See the MongoDB documentation for more usage scenarios - http://dochub.mongodb.org/co
re/commands
         *
         * <code>
         * $this->mongo_db->command(array('geoNear'=>'buildings', 'near'=>array(53.228482, -0.547847), 'num' => 10, 'nearSphere'=>true));
         * </code>
         *
         * @param array $query The command query
         *
         * @access public
         * @return object
         */
        public function command($query = array())
        {
                try
                {
                        $execute = $this->db->command($query);
                        return $execute;
                }

                catch (MongoCursorException $exception)
                {
                        show_error('MongoDB command failed to execute: ' . $exception->getMessage(), 500);
                }
        }

Updates Options Overidden

Hi,

First of all, thanks for sharing this.

I think this is a bug;
The passed $options was cancelled by defaulting values. It should be the other way around.

// Mongo_db->update()
1244: - $options = array_merge($options, array('w' => $this->write_concerns, 'j'=>$this->journal, 'multiple' => FALSE));
1244: +$options = array_merge(array('w' => $this->write_concerns, 'j'=>$this->journal, 'multiple' => FALSE), $options);
// Mongo_db->update_all()
1284: - $options = array_merge($options, array('w' => $this->write_concerns, 'j'=>$this->journal, 'multiple' => TRUE));
1284: + $options = array_merge(array('w' => $this->write_concerns, 'j'=>$this->journal, 'multiple' => TRUE), $options);

Connection error to /tmp/mongodb-27017.sock

In current version PORT is required. When it is necessary to be connected to /tmp/mongodb-27017.sock if i typed PORT, i see PHP error that file /tmp/mongodb-27017.sock:27017 is undefined.

Your dns-constructor:
$dns = "mongodb://{$this->hostname}:{$this->port}/{$this->database}";

You shall add additional check on empty of PORT. For this purpose it is necessary to change functions: prepare & connect.

Convert this library to a standalone library.

Hi @intekhabrizvi,
I create this issue because I dont see any contact information from your profile.
I love and using your library in my projects. But I working on many kind of project such as ZF, Slim, etc ...
May you allow me to copy and convert your library to a standalone library so we can use it in any kinds of php project not just CodeIgniter?
My library will be hosted as a public repository in Github and have a copyright and link to your main repository.
Please give me your opinion.

Thank you!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.