php-mongodb

Nested Relations MongoDb

别说谁变了你拦得住时间么 提交于 2021-01-29 17:33:59
问题 I need some help. I have 2 MongoDB collections that I want to relate. One is for categories and the other for multimedia content. A category can contain one multimedia content and Many Childs Categories. After execute aggregation by passing the pipeline I get the Returned Format (See image 1): Media elements inside Category.Media and Child categories inside Category.Childs. My problem is that I don't know how I can insert again Media inside Child Categories (See image 2) I also leave below

PHP mongodb driver check connection

狂风中的少年 提交于 2019-12-31 05:26:08
问题 Trying to check connection with mongodb server using php driver manager! I googled many times to get the method like $DriverManager->checkConnection() or any property like $DBmanager->connected ! Current output from php var_dump MongoDB\Driver\Manager object(MongoDB\Driver\Manager)#10 (2) { ["uri"]=> string(24) "mongodb://127.0.0.1:27017" ["cluster"]=> array(0) { } } I checked by starting the database server and then without running the server! There is no difference between var_dump results!

PHP72 MongoDB driver with Homebrew on OSX

老子叫甜甜 提交于 2019-12-23 02:39:26
问题 I have a question that might point to a misunderstanding I have with Homebrew in relation to MongoDB: I am running XAMPP (version) with PHP 7.2.1 (which I want to use) on Mac OSX 10.12.6 (Sierra). I installed MongoDB and created configuration and data storage folder. It runs fine on command line (when using mongod and mongodb by terminal). Now, I want to install the PHP driver for PHP 7.2.1. I followed the instructions on http://php.net/manual/en/mongodb.installation.homebrew.php and adapted

$expr arrayElementAt not working in aggregation for embedded document

守給你的承諾、 提交于 2019-12-20 03:56:09
问题 I am doing mongo db aggregation like $cursor = $this->collection->aggregate( array( array( '$project' => array( 'FullName' => array('$concat' => array('$first_name', ' ', '$middle_name', ' ', '$last_name')), 'FirstMiddle' => array('$concat' => array('$first_name', ' ', '$middle_name')), 'FirstLast' => array('$concat' => array('$first_name', ' ', '$last_name')), 'FirstName' => array('$concat' => array('$first_name')), 'MiddleName' => array('$concat' => array('$middle_name')), 'LastName' =>

How to get cursor result count using the MongoDB PHP extension

邮差的信 提交于 2019-12-13 01:34:31
问题 The mongo PHP extension is deprecated in favour of the mongodb extension. This extension is used together with the mongo-php-library. In the old extension one could get the result count from the cursor using MongoCursor::count(). However, the new cursor MongoDB\Driver\Cursor has no such method. What is the new way of getting the number of results from after performing a query against MongoDB? 回答1: I use this code. $query = ["hello" => "world"]; $command = new MongoDB\Driver\Command(["count" =

MongoDB no suitable servers found

社会主义新天地 提交于 2019-12-12 09:38:42
问题 I'm having trouble connecting to a replica set. [MongoDB\Driver\Exception\ConnectionTimeoutException] No suitable servers found (`serverSelectionTryOnce` set): [Server closed connection. calling ismaster on 'a.mongodb.net:27017'] [Server closed connection. calling ismaster on 'b.mongodb.net:27017'] [Server closed connection. calling ismaster on 'c.mongodb.net:27017'] I however, can connect using MongoChef 回答1: Switching any localhost references to 127.0.0.1 helped me. There is a difference

Set filter with regex in query with PHP's MongoDB\Driver\Query class

你。 提交于 2019-12-10 18:23:14
问题 Using MongoDB with PHP's MongoDB driver I am not able to filter search results with regular expressions. In the manual there are no examples given how to use the "filter" option: MongoDB\Driver\Query. $manager = new MongoDB\Driver\Manager("mongodb://localhost:27017"); $filter = array(?????); $options = array("projection" => array("fieldname" => 1)); $query = new MongoDB\Driver\Query($filter, $options); $cursor = $manager->executeQuery("dbname.collectionname", $query); foreach($cursor as

How to code MongoDB foreach Query in PHP

这一生的挚爱 提交于 2019-12-10 11:40:00
问题 How to code MongoDB foreach Query in PHP ? Now i have to code the same MONGODB QUERY in PHP with iterator_to_array , i don't know how to get this query to execute in PHP. Now i stucked in this. i have given my data with some example. USED MONGO QUERY: db.getCollection('DRUM').find({'CODE': 'XXYYZZYY'}).forEach( function(doc) { print(doc.COLLECTION.DAY); }); Actual DB RECORD: { "CODE" : "XXYYZZYY", "COLLECTION" : { "DAY" : { "2017-06-05" : { "id" : 565455 }, "2017-06-15" : { "id" : 565445 } },

How to convert below MongoDB query into PHP?

丶灬走出姿态 提交于 2019-12-06 15:24:21
问题 Below query worked fine in Studio 3T and Robomongo, But I want to convert it into PHP format, Following is my query, db.news.aggregate([ { $match: { "_id" : "1" } }, { "$project": { "comments": { "$filter": { "input": "$comments", "as": "comment", "cond": { "$eq": [ "$$comment.status", "active" ] } } } } }, { "$project": { "comments": { "$slice": [ { "$slice": [ "$comments", { "$subtract": [ { "$size": [ "$comments" ] }, 1 ] } ] }, -1 ] } } }]) I have tried below, But it giving error " Error:

MongoDB no suitable servers found

六眼飞鱼酱① 提交于 2019-12-05 05:57:40
I'm having trouble connecting to a replica set. [MongoDB\Driver\Exception\ConnectionTimeoutException] No suitable servers found (`serverSelectionTryOnce` set): [Server closed connection. calling ismaster on 'a.mongodb.net:27017'] [Server closed connection. calling ismaster on 'b.mongodb.net:27017'] [Server closed connection. calling ismaster on 'c.mongodb.net:27017'] I however, can connect using MongoChef Switching any localhost references to 127.0.0.1 helped me. There is a difference between localhost and 127.0.0.1 See: localhost vs. 127.0.0.1 MongoDB can be set to run on a UNIX socket or TCP