mongodb-php

How machine id/host name is mapped/demapped to 3 byte in object id?

巧了我就是萌 提交于 2019-12-13 13:14:17
问题 How machine id/host name is mapped/demapped to 3 byte in object id? And where should i look for machine id in linux? domU-12-31-39-13-02-56 looks very strange and i am not sure it's correct or not? <?php $id = new MongoId('4f7351390c211d0a3d000004'); print_r($id->getHostname()); //domU-12-31-39-13-02-56 ?> 回答1: That function is not getting your hostname from the ObjectID, it shows you what hostname PHP is using to generate the unique IDs: http://php.net/manual/en/mongoid.gethostname.php The

Installing and starting MongoDB for PHP on Ubuntu 12.04

亡梦爱人 提交于 2019-12-12 22:13:22
问题 I have installed the mongo extension from PECL and added it to my php.ini file. The extension loads when I run phpinfo(); but shows me this error when I try to connect to the Mongo Server. Fatal error: Uncaught exception 'MongoConnectionException' with message 'Transport endpoint is not connected' in /var/www/mongo.php:2 Stack trace: #0 /var/www/mongo.php(2): Mongo->__construct() #1 {main} thrown in /var/www/mongo.php on line 2 phpinfo(); tells me its running on localhost at the default port.

MongoDB PHP Driver: Using Execute for Stored JS

假如想象 提交于 2019-12-12 00:28:17
问题 I created a Stored JS function which supposedly completes a very tedious job, faster and efficiently. Now after a investing long working hours I came up with completing this functionality. So my function is suppose myFunc(); db.system.js.save( { _id : "myFunc" , value : function (param1,param2,param3....){ ... }}); Once I was through with completing this function, and testing it with Mongo Shell as db.eval("myFunc('a','b'...)"); and db.loadServerScripts(); myFunc('a','b',..); I was satisfied

PHP MongoDB execute() locking collection

淺唱寂寞╮ 提交于 2019-12-11 18:36:25
问题 I'm using MongoDB over the command line to go loop through a bunch of documents for a particular condition, move from one collection to another collection and removing from the original collection. db.coll1.find({'status' : 'DELETED'}).forEach( function(e) {db.deleted.insert(e); db.coll1.remove({_id:e._id}); }); This works however I need to script this so it moves all the documents in coll1 to the deleted collection everyday (or every hour) via a cron script. I'm using PHP so I figured I

php-driver for mogodb wont't compile

人盡茶涼 提交于 2019-12-11 10:36:36
问题 Centos 6.6 x86_64 kernel version 2.6(something) I am trying to compile php-driver(downloaded the zip file from git) for mongoDB but it gives error during make all This is the compile error /bin/sh /usr/local/mongo-php-driver/libtool --mode=compile cc -I./util -I. -I/usr/local/mongo-php-driver -DPHP_ATOM_INC -I/usr/local/mongo-php-driver/include -I/usr/local/mongo-php-driver/main -I/usr/local/mongo-php-driver -I/usr/local/include/php -I/usr/local/include/php/main -I/usr/local/include/php/TSRM

Persistent connections with new Mongo PHP driver

吃可爱长大的小学妹 提交于 2019-12-11 05:47:33
问题 For a project I am using the new MongoDB driver for PHP with the library (see: https://docs.mongodb.com/php-library/master/), not the legacy one. We are running PHP 7 as FPM. I recently did some profiling with XDEBUG and realized that the first database query is significantly slower than the second one, for example Session::validate -> Account::find 38ms getProfile -> Account::find 2ms Where Account::find would execute the query to obtain one document by its _id and both calls look up

mongodb - Finding the Sum of a field (if it exists) in a collection

一个人想着一个人 提交于 2019-12-11 03:14:12
问题 I have the following mongodb structure { "_id": ObjectId("507c80a143188f9610000003"), "date": ISODate("2012-10-15T21: 31: 13.0Z"), "uid": NumberInt(35920), "comp": NumberInt(770), "fields": { "rating": { "parent": "rating", "weight": NumberInt(2), "rel_weight": 0.11, }, "capacity": { "parent": "capacity", "weight": NumberInt(4), "rel_weight": 0.89, }, } } The "fields" attribute has 2 fields "rating" and "capacity" in it. But, each entry might have a different set of fields. eg. dimension,

SASL Authentication failed on Mongodb database

拜拜、爱过 提交于 2019-12-10 18:47:35
问题 I-m having an issue trying connect to Mongodb using PHP Mongodb driver. Actually I have a database called LRS and it has a user called "juano" with a pwd:"12345" in my settings file I-m sure that I wrote the correct configuration. But when I load my homepage in Laravel I receive this message: MongoConnectionException (71) HELP Failed to connect to: localhost:27017: SASL Authentication failed on database'LRS': Authentication failed. More specific the error found here if (isset($config[

mongodb aggregation framework group by two fields

被刻印的时光 ゝ 提交于 2019-12-10 15:05:35
问题 I'm querying my database using aggregation and pipeline, with two separate queries: $groups_q = array( '$group' => array( '_id' => '$group_name', 'total_sum' => array('$sum' => 1) ) ); $statuses_q = array( '$group' => array( '_id' => '$user_status', 'total_sum' => array('$sum' => 1) ) ); $data['statuses'] = $this->mongo_db->aggregate('users',$statuses_q); $data['groups'] = $this->mongo_db->aggregate('users',$groups_q); And I'm getting what I want: Array ( [statuses] => Array ( [result] =>

PHP MongoDB update multiple documents using $in/$or

随声附和 提交于 2019-12-10 14:42:35
问题 I'm having trouble figuring out how to construct an update query in PHP that will update document IDs X,Y, and Z. Does anyone have experience with this? $ids[] = array( new MongoId('4eaaf929498fe2c80300000c'), new MongoId('4eaaff24498fe2ba0900001f') ); $collection->update( array('_id' => array('$in' => $ids)), array('$set' => array("title"=>"test")), array("upsert" => true) ); 回答1: I assume that your trouble is, that only one document get's updated, right? If this is the case, there is