php-mongodb

How to convert below MongoDB query into PHP?

我与影子孤独终老i 提交于 2019-12-04 21:54:20
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: localhost:27017: FieldPath field names may not be empty strings. " PHP converted sample: <?php

Handling unwind for the non existing embedded document [duplicate]

不羁岁月 提交于 2019-12-04 05:07:01
问题 This question already has answers here : $unwind empty array (2 answers) Closed last year . I am performing aggregation on employees table to fetch some hostel details with projection like $query = ['_id' => new MongoDB\BSON\ObjectID($this->EmployeeId)]; $pipeline = array( ['$match' => $query], [ '$addFields'=> [ 'assigned_master_keys'=> [ '$cond'=> [ 'if'=> [ '$ne'=> [ [ '$type'=> '$assigned_master_keys' ], 'array' ] ], 'then'=> [], 'else'=> '$assigned_master_keys' ] ] ]], ['$unwind'=> '

Handling unwind for the non existing embedded document [duplicate]

只愿长相守 提交于 2019-12-02 06:27:21
This question already has an answer here: $unwind empty array 2 answers I am performing aggregation on employees table to fetch some hostel details with projection like $query = ['_id' => new MongoDB\BSON\ObjectID($this->EmployeeId)]; $pipeline = array( ['$match' => $query], [ '$addFields'=> [ 'assigned_master_keys'=> [ '$cond'=> [ 'if'=> [ '$ne'=> [ [ '$type'=> '$assigned_master_keys' ], 'array' ] ], 'then'=> [], 'else'=> '$assigned_master_keys' ] ] ]], ['$unwind'=> '$assigned_master_keys'], ['$lookup' => [ 'from' => 'HostelTbl', 'let' => [ 'hostelid' => '$assigned_master_keys.hostel_id' ],

PHP MongoDB - Use of the aggregate command without the cursor option is deprecated. What?

怎甘沉沦 提交于 2019-11-29 04:11:57
I have updated mongo and now in the log the following error appears: Use of the aggregate command without the cursor option is deprecated Mongo says that I should put a second REQUIRED parameter to aggregate function, because my current usage is deprecated. I currently use the following code PHP (now is deprecated): $this->db->{$collection}->aggregate($options); And return this format: {"result":[ { "_id":"xxxxxx", "update":[ { "firstUpdateTime":xxxxxx, "updateTime":xxxxxxx, } ], "media":[ { "xxxx":{ ... To not use an deprecated code I add the new second parameter (but I do not understand what

PHP MongoDB - Use of the aggregate command without the cursor option is deprecated. What?

China☆狼群 提交于 2019-11-27 18:07:39
问题 I have updated mongo and now in the log the following error appears: Use of the aggregate command without the cursor option is deprecated Mongo says that I should put a second REQUIRED parameter to aggregate function, because my current usage is deprecated. I currently use the following code PHP (now is deprecated): $this->db->{$collection}->aggregate($options); And return this format: {"result":[ { "_id":"xxxxxx", "update":[ { "firstUpdateTime":xxxxxx, "updateTime":xxxxxxx, } ], "media":[ {

Installing the PHP 7 MongoDB Client/Driver?

怎甘沉沦 提交于 2019-11-26 12:18:57
问题 I am very eager to start working with PHP 7 however one issue is getting in the way... I primarily use MongoDB for the database, and the problem is that I don\'t know how to install the MongoDB driver/client for PHP 7. My current installation is PHP 5.6 and on my Mac and brew install php56-mongo does the trick. Can anyone recommend how I can get this working on my Mac or an Ubuntu install? Thanks in advance and much appreciated! 回答1: The Mongo extension for PHP Version 5.99.99 or older has