mongodb-php

MongoCollection::aggregate() is undefined in Heroku PHP using MongoHQ

扶醉桌前 提交于 2019-12-25 01:50:02
问题 I'm getting the following error when using MongoDB's aggregate() function in a PHP code. This code perfectly works on my local setup which is running MongoDB 2.2.3 PHP Fatal error: Call to undefined method MongoCollection::aggregate() in /app/www/page.php on line 52, referer: http://referrer.url Code foreach($cats as $key=>$val){ $cats2[$val['lable']] = $myCollection->aggregate( array( array('$match' => array('user_id' => $user_id )), array('$unwind' =>"\$data"), array('$match' => array('data

php json_encode doesn't result in real object / make array string into real object / turn php array into json

谁说我不能喝 提交于 2019-12-24 12:16:16
问题 Here is my PHP code, it's getting a listing of collections from mongodb $list = $db->dbname->listCollections(); $result = array(); $i=0; foreach ($list as $thiscollection) { $result[$i++] = $thiscollection->getName(); } echo json_encode( $result ); I do console.log in the callback and this is what I see. ["fruits", "dogs", "cars", "countries"] The problem is that this is a string, not an array. I need to iterate through these values. How an I make this into a real object or get php to give me

mongoDB updateOne not updating a record

有些话、适合烂在心里 提交于 2019-12-24 08:40:24
问题 I am trying to update a record in mongoDB using updateOne, the un updating record is in array, and all fields are updating except one field which is country , I have tried to update it using MongoChef (a GUI of MongoDB for linux), but it doesn't work, also If I update one the Document using Edit in GUI then that record is ready to update after that . I have tried with the following query in MongoChef db.institutions.updateOne({ "campus": { "$elemMatch": { "_id": ObjectId(

MongoConnectionException - Failed to connect to: localhost:27017 [closed]

蓝咒 提交于 2019-12-22 09:27:28
问题 This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center. Closed 6 years ago . I used the following PHP code to connect to MongoDB: $m = new MongoClient("mongodb://localhost:27017"); However, I am getting the following error: Fatal

Mongodb date is off by 1 hour

岁酱吖の 提交于 2019-12-21 20:36:22
问题 I am running mongodb on ubuntu server. The server time is root# date Thu Sep 13 21:15:58 BST 2012 But when I run the following command I get a different result root# mongo MongoDB shell version: 2.2.0 connecting to: test > new Date() ISODate("2012-09-13T20:15:58.670Z") There is exactly one hour difference. When I update a documents updated_on field with php using MongoDate() , the value of the field is still 1 hour off. [EDIT] Actually I just checked my php error log and the time in the log

MongoConnectionException - No candidate servers found

人盡茶涼 提交于 2019-12-21 04:39:08
问题 I am developing a PHP web application using a MongoDB replicaset to store my data. I occasionally receive the following error: Fatal error: Uncaught exception 'MongoConnectionException' with message 'No candidate servers found' I have a 3 member Mongo replica set with 1 arbiter rs0:PRIMARY> rs.status() { "set" : "rs0", "date" : ISODate("2013-01-30T01:04:04Z"), "myState" : 1, "members" : [ { "_id" : 0, "name" : "JenEricsMacPro.local:27017", "health" : 1, "state" : 1, "stateStr" : "PRIMARY",

$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' =>

Sorting MongoDB GeoNear results by something other than distance?

試著忘記壹切 提交于 2019-12-19 09:02:53
问题 I'm developing a PHP application in which we need to retrieve results within a certain boundary, but ordered by the create date of the results, not the distance. I figured MongoDB's geoNear command would be great for this, since it takes care of calculating the distance for each result. However, I was wondering if there was a way to specify sorting by the create_date attribute, rather than distance. Ideally I would create a compound key index of coordinates and create date, and then quickly

MongoDB, MapReduce and sorting

半腔热情 提交于 2019-12-17 15:44:59
问题 I might be a bit in over my head on this as I'm still learning the ins and outs of MongoDB, but here goes. Right now I'm working on a tool to search/filter through a dataset, sort it by an arbitrary datapoint (eg. popularity) and then group it by an id. The only way I see I can do this is through Mongo's MapReduce functionality. I can't use .group() because I'm working with more than 10,000 keys and I also need to be able to sort the dataset. My MapReduce code is working just fine, except for

How to have eclipse resolve php classes in MongoDB\BSON namespace?

风流意气都作罢 提交于 2019-12-13 15:17:43
问题 After many comes and goes I managed to install the MongoDB Driver for PHP 5.6 and made it work on OSX El Capitan. (The way it worked was using Homebrew ) To start working on a project I created the folder for the project and using Composer installed the required packages I needed. Between theese packages I required mongodb/mongodb which is the recomended mongo php library to use by the php Manual on line and in the driver github page. The problem I found is that Eclipse is resolving the