Code Monkey home page Code Monkey logo

codeigniter-mongodb-library's People

Contributors

intekhabrizvi avatar najdanovicivan 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

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

codeigniter-mongodb-library's Issues

Class 'CI_Mongo_db' not found

I'm ugrading
codeigniter 2x to 3.1.1, php5.6 to 7.2, mongodb 3.4 to 3.6 im facing this issue

Type: Error
Message: Class 'CI_Mongo_db' not found
Filename: /var/www/html/main_code/system/core/Common.php
Line Number: 196

also im getting this error
A PHP Error was encountered
Severity: Core Warning
Message: Module 'mongodb' already loaded
Filename: Unknown
Line Number: 0
Backtrace:

Can anyone help me with this..thank you.

Distinct Query don't work!!

Hi,
I try made $this->mongo_db->distinct("") from library bu get errors like this:

A PHP Error was encountered
Severity: Notice

Message: Undefined property: MongoDB\Driver\Manager::$match

Filename: libraries/Mongo_db.php

Line Number: 1336

Backtrace:

File: C:\etc\www\folder\application\libraries\Mongo_db.php
Line: 1336
Function: _error_handler

File: C:\etc\www\folder\application\controllers\inicio.php
Line: 21
Function: distinct

File: C:\etc\www\folder\index.php
Line: 315
Function: require_once

An uncaught Exception was encountered
Type: Error

Message: Call to a member function distinct() on null

Filename: C:\etc\www\folder\application\libraries\Mongo_db.php

Line Number: 1336

Backtrace:

File: C:\etc\www\folder\application\controllers\inicio.php
Line: 21
Function: distinct

File: C:\etc\www\folder\index.php
Line: 315
Function: require_once

I need some help urgent, please!!!

constructor failed with class not exists error

Hi, my development is installed with lnmp all-in-one package:
PHP Version 7.2.9
MongoDB extension version | 1.5.2
CodeIgniter:3.1.7

and after I implemented the CIMongo library in autoload config, then the page shows error:
"The MongoDB PECL extension has not been installed or enabled"

I did check my php-fpm environment with phpinfo and it showed mongodb extension enabled.
I checked the source and found this error was raised by
if ( ! class_exists('MongoDB')) { show_error("The MongoDB PECL extension has not been installed or enabled", 500); }
I checked another ci mongo lib on github, and it used another way to check if the library exist with a full namespace
https://github.com/verkhoumov/codeigniter-mongodb-library/blob/master/application/libraries/Mongo_db.php#L203

Is there anything wrong with my implementation?

$this->mongo_db->aggregate() param confusion

Dear Mr. Intekhab Rizvi,

I have a question related to $this->mongo_db->aggregate('collection', $opts) parameters

according to the documentation $opts is an array containing pipeline stages,

my concern is, how to add 'cursor' param in the $opts array??? thanks

regards

Understand the pull Function

Hello, I do not understand the pull Funktion

name: "Documents"
fileTypes:
0:".doc"
1:".docx"
2:"test"

this is my data row

I will remove the filetypes value test with the array index 2

I try this but it did not work.
$this->mongo_db->pull('fileTypes', array('2'))->update('blog_posts');

What is with the where Function ?
I have more data rows
I did also try it with where('name' => 'Documents') but it also not work.

$this->mongo_db->like('foo', 'bar', 'im', FALSE, TRUE);

work using this

public function like($field = "", $value = "", $flags = "i", $enable_start_wildcard = TRUE, $enable_end_wildcard = TRUE)
{
if (empty($field)) {
show_error("Mongo field is require to perform like query.", 500);
}

	if (empty($value)) {
		show_error("Mongo field's value is require to like query.", 500);
	}

	$field = (string) trim($field);
	$this->_w($field);
	if ($enable_start_wildcard !== TRUE) {
		$value = "^" . $value;
	}
	if ($enable_end_wildcard !== TRUE) {
		$value .= "$";
	}
	$this->wheres[$field] = new MongoDB\BSON\Regex($value, $flags);
	return ($this);
}

Full-Text Search

Hello it's amazing library. I want to ask how i can use Full-Text Search ?

MongoDB\Driver\Exception\InvalidArgumentException

Type: MongoDB\Driver\Exception\InvalidArgumentException

Message: MongoDB\BSON\ObjectId::__construct() expects parameter 1 to be string, object given

[_id] => stdClass Object
(
[$id] => 5d78dd3d953b9c43aa194cb9
)
print_r((string) new MongoDB\BSON\ObjectId($campaignData['_id']));

Need Help How do I perform a query with the library where I need to select the last records recorded and grouped by an element.

How do I perform a query with the library where I need to select the last records recorded and grouped by an element.
the colection name is ExampleCol and the elements _id, Hexample, Hdate

In MYSQL i do this ( SELECT * FROM TABLE WHERE CONDS GROUP BY COLUMN NAME)
In MONGO DB I had a success using this code.

db.ExampleCol.aggregate(
[
{ $sort: { HDate: -1, Hexample: -1 } },
{
$group:
{
_id: "$_Hexample",
"_Hexample": {"$last":"$_Hexample"},
lastHDate: { $last: "$HDate" }
}
}
]
)

How to Mount a query using ur library?
I tried....
$this->mongo_db->aggregate(); -not success;
$this->mongo_db->command(); -not success;

Need help with customized version of CI mongodb library for php 5.6

Hi I have a CI project that uses PHP with MongoDB and have been having problems of recent.

Can you help with a revised version of your mongodb library for PHP 5.6 (https://github.com/intekhabrizvi/codeigniter-mongodb-library) since you already have this one for PHP 7. Would really appreciate it.

When I use this PHP 5.6 version (https://github.com/laredy27/) that was done by another contributor that was inspired by your legacy version, It keeps throwing this error:

_Fatal error: Call to undefined method MongoDB\Driver\Manager::selectDatabase() in /home/getqwikpay/web/getqwikpay.com.ng/public_html/application/libraries/Mongo_db.php on line 230
A PHP Error was encountered
Severity: Error

Message: Call to undefined method MongoDB\Driver\Manager::selectDatabase()

Filename: libraries/Mongo_db.php

Line Number: 230

Backtrace:_

I have been trying to get it to work for a week now with no progress at all.
I have attempted various ways to troubleshoot it and could not get any resolution. I thought it could be driver compatibility issue but not at all. I have check to see if there are any auto loading issues with the mongodb driver library and can't quite verify this.

Here is my current platform setup is:
Linux (Ubuntu 16)
PHP 5.6 on CodeIgniter 3
Mongodb 3.4 (database)

Installed modules - MongoDB extension 1.3.0
Other dependencies all duly installed

MongoDB driver installed (via composer)

  • mongodb/mongodb ~1.2.0

NB:
I have already tried to upgrade the PHP extension to the latest 1.5.2 with the latest composer mongodb library at 1.4.2 added and still had exception errors.

Looking forward to your response.

Kind regards

Update method is not clearing after execution

Hi, I ran into a strange issue when I try to update one single document each time in a loop function,
I found the update data is getting bigger and bigger as the loop went on, and every new update seemed to have old data added in the previous loop.

I checked the soucrce code and found that _clear function is not called either in update or update_all in the new lib, while I saw that function called in legacy version of this library

Could this missing function be the reason?

Class 'MongoRegex' not found

i used like function and i got this error

Class 'MongoRegex' not found

this line $this->wheres[$field] = new MongoRegex($regex);
line 834 on Mongo_db.php

Search in array of objects - $elemMatch

Hello Intekhab Rizvi,

in the function select is a Komment //support $elemMatch in select
but if i try this as select:
$select = array('$elemMatch'=>array("Identity"=> "SYSTEM"));
I got the error:
Type: MongoDB\Driver\Exception\CommandException
Message: Unsupported projection option: $elemMatch: { Identity: "SYSTEM" }

How must i use this in the Select

Missing parameters in delete_all and delete

After read the comments: delete document from the passed collection based upon certain criteria, and the examples of usage: $this->mongo_db->delete_all('foo', $data = array());

The functions doesn't get the second parameter (criterias), then delete_all and delete works equally?

Beside that, remove_index are doing a wrong check (empty ($ keys)) when not receive $keys but it is $name

Delete Params Invalid compared to official document

$bulk->delete($this->wheres, $this->updates, $options);

PHP official doc provided an example , and it only has two params while the code above used three, same thing happened on delete_all function, pls check it out
`<?php

$bulk = new MongoDB\Driver\BulkWrite;
$bulk->delete(['x' => 1], ['limit' => 1]);
$bulk->delete(['x' => 2], ['limit' => 0]);

$manager = new MongoDB\Driver\Manager('mongodb://localhost:27017');
$result = $manager->executeBulkWrite('db.collection', $bulk);

?>`

How to select nested object field or use them in the where clause?

For an example, here's my parent object - project :

project = { tasks : [ { task_id: "123", task_name: "Some task", } ] }

$this->mongo_db->select(array("task"))->get("projects") - this will fetch the whole tasks object.

But I want to select task_name of each tasks. I tried few things but it didn't work.

select(array("task.task_name")) does not work. I also tried it in the where clause,
$this->mongo_db->where('task.task_name' , "Some task"); , but it also didn't work. Any kind help would be highly appreciated. Thanks.

MongoDB\Driver\Exception\InvalidArgumentException

MongoDB\Driver\ReadPreference::__construct() expects parameter 1 to be integer, string given
Line Number: 841

Backtrace:

File: /usr/share/nginx/html/travelweb/application/libraries/Mongo_db.php
Line: 841
Function: __construct

'The 'cursor' option is required' error while using the aggregation

I have this following data in a collection named 'projects' :

{
name: 'Some name 1',
category: 'Category A'
}
{
name: 'Some name 1',
category: 'Category A'
}
{
name: 'Some name 1',
category: 'Category B'
}
{
name: 'Some name 1',
category: 'Category B'
}

I am trying to use aggregate to to group the data and put a limit (let's assume limit = 1 here) for each group so that the result would like this -

{
name: 'Some name 1',
category: 'Category A'
}
{
name: 'Some name 1',
category: 'Category B'
}

Here's how I am trying -

 $ops = [
    ['$group' => ['_id' => 'program']],
    ['$limit' => 1]
 ];
 $this->mongo_db->aggregate('projects', $ops);

But I am getting the following error -

Type: MongoDB\Driver\Exception\CommandException
Message: The 'cursor' option is required, except for aggregate with the explain argument

Am I writing the aggregation syntax in proper way. I am still learning. A sample code for this type of scenario would be really helpful for me. Thanks.
note: I am using mongo 4.0.10

geoNear search fails

Hi!

I'm trying to do a geoNear search in a collection with a 2dsphere index using:

$POIs = $lMongo ->command([ 'geoNear' => 'pois', 'near' => [ 'type' => 'Point', 'coordinates' => [$longitude, $latitude] ], 'maxDistance' => $maxDistance, 'nearSphere' => TRUE ]);

But it does not work. It' always says "MongoDB query failed" and i don't know what is wrong. Any help?

Thanks and best regards!

Authentication failed

{
"status": false,
"error": {
"classname": "MongoDB\Driver\Exception\AuthenticationException",
"message": "Authentication failed."
}
}

I have entered correct username and password still it gives me that error in below method.

$cursor = $this->db->executeQuery($this->database.".".$collection, $query, $read_preference);

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.