mongodb-php

MongoDB - PHP - MongoCursorException 'Cursor not found'

旧巷老猫 提交于 2019-12-05 07:43:52
I have 2 collections: A (3.8M docs) and B (1.7M docs) I have a PHP script that I run from the shell that: loops over each record in A ~60% of the time, it does a findOne on B (using _id) does some basic math, creating a php array once the loop on all docs in a is done: 4) loop over php array 5)upsert into collection C during (1), I consistently get: PHP Fatal error: Uncaught exception 'MongoCursorException' with message 'Cursor not found' The last item processed was #8187 of 3872494. real 1m25.478s user 0m0.076s sys 0m0.064s Running it again, with no change in code, the exception got thrown at

Mongodb nested array search

£可爱£侵袭症+ 提交于 2019-12-05 06:47:26
问题 document structure example is: { "dob": "12-13-2001", "name": "Kam", "visits": { "0": { "service_date": "12-5-2011", "payment": "40", "chk_number": "1234455", }, "1": { "service_date": "12-15-2011", "payment": "45", "chk_number": "3461234", }, "2": { "service_date": "12-25-2011", "payment": "25", "chk_number": "9821234", } } } { "dob": "10-01-1998", "name": "Sam", "visits": { "0": { "service_date": "12-5-2011", "payment": "30", "chk_number": "86786464", }, "1": { "service_date": "12-15-2011",

Decoding JSON using PHP from Mongo

天大地大妈咪最大 提交于 2019-12-05 05:56:06
问题 I've already looked at this thread: PHP decode nested JSON and haven't managed to use it to solve my problem. I am currently grabbing a JSON object from Mongo, and I'm having issues grabbing information from nested objects. { "adminLevel" : 200, "chat" : true, "clans" : [ BinData(0,"wcXHR577OVBXfy9JwEf5gQAAAAAAAAAAAAAAAAAAAAAAAAAAAA") ], "experience" : NumberLong(70003), "kitNew" : { "converted" : true, "items" : { "ak47" : { "killCount" : 5, "selected" : false, "unlocked" : 1 }, "hub-knife"

how to ignore duplicate documents when using insertMany in mongodb php library?

久未见 提交于 2019-12-05 00:13:49
I am using mongo php library , and trying to insert some old data into mongodb. I used insertMany() method and pass a huge array of document, that may have duplicate documents on unique indexes. Lets say I have a users collection and have these indexes: [ { "v" : 1, "key" : { "_id" : 1 }, "name" : "_id_", "ns" : "test.users" }, { "v" : 1, "unique" : true, "key" : { "email" : 1 }, "name" : "shop_id_1_title_1", "ns" : "test.users" } ] If there's a duplicate document, MongoDB\Driver\Exception\BulkWriteException would raise and stop the process. I want to find a way to ignore inserting duplicate

MongoDB PHP using $in with array

Deadly 提交于 2019-12-04 20:59:24
问题 I'm using MongoDB and PHP and trying to do a $in based on a generated array. When I specify the same array manually, it works, but when I build it, it return any results with the same data. There's what I have: $settings = array(); foreach($items as $item) { $settings[] = $item['id']; } //Settings is the same as this $setting2 = array(1,2,3,4,5,6,7,8); //This returns no results $cursor = $collection->find(array('status' => 0, 'sid' => array('$in' => $settings))); //This does return results

Mongodb date is off by 1 hour

こ雲淡風輕ζ 提交于 2019-12-04 12:53:27
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 file is 1 hour off as well [13-Sep-2012 20:11:14 UTC] Log Message (Time should be 21:11:14) Mongo tells

PHP: Is it bad design to serialize objects and stick them in the database for later?

本小妞迷上赌 提交于 2019-12-04 09:53:30
I am planning and researching my switch from MySQL to MongoDB right now and I just had an interesting thought... I have a bunch of hierarchical objects that I need to store in the database. My current method is to have a bunch of embedded documents in a collection. They will never need to be searched for. Would it possibly make sense just to serialize the PHP objects, stick them in the DB, and then unserialize them back into PHP objects when I want to use them? The alternative is using Doctrine as my ORM. My programming intuition tells me that this is bad design and is limiting, but I feel

Mongo Map Reduce first time

北慕城南 提交于 2019-12-04 07:42:00
问题 First time Map/Reduce user here, and using MongoDB. I have a lot of page visit data which I'd like to make some sense of by using Map/Reduce. Below is basically what I want to do, but as a total beginner a Map/Reduce, I think this is above my knowledge! Go through all the pages with visits in the last 30 days, and where external = true. Then for each page, find all visits Group all visits by referral location For each referral location, calculate how many then went to visit a page which has a

What happens when connections to MongoDB are not closed?

大憨熊 提交于 2019-12-04 07:25:12
I have the following PHP script that basically connects to the MongoDB, writes a document and then closes the connection 19000 times: <?php for($i=0; $i < 19000; $i++) { $con = new Mongo("mongodb://localhost:27017"); $db = $con->selectDB('test'); $col = $db->selectCollection('close_wait_test'); $col->insert(array('Test' => 'Value1')); $con->close(); } ?> Running this script once works fine, but if I run the script a few seconds later, I get the 'Cannot assign requested address' exception, which is understandable as the server system probably ran out of ports. If however, I remove $con->close()

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