intekhabrizvi / codeigniter-mongodb-library Goto Github PK
View Code? Open in Web Editor NEWCodeigniter Mongodb library for Codeigniter 3, PHP 7+ & mongodb 1.5.x extension
License: MIT License
Codeigniter Mongodb library for Codeigniter 3, PHP 7+ & mongodb 1.5.x extension
License: MIT License
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.
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!!!
I have the same issues like this
https://github.com/intekhabrizvi/codeigniter-mongodb-library/issues/25
but i don't understand the solve
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?
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
Or how can I convert my connection string to the variables in config?
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.
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);
}
Hello it's amazing library. I want to ask how i can use Full-Text Search ?
http://php.net/manual/zh/mongocollection.update.php
old driver used 'multiple' while MongoDB\Driver\BulkWrite use 'multi'
http://php.net/manual/zh/mongodb-driver-bulkwrite.update.php
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']));
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;
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)
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
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?
we want transactions in mongodb
or_like()
not_like()
or_not_like()
thank you very much
The above url gives us a fixibility to find and search content. Please integrate the find option.
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
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
@Usage : $this->mongo_db->count('foo');
count are very slow when there are 100,000 data.
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
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);
?>`
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\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
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
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!
{
"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);
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.