Questions tagged [mongodb-php]

MongoDB is a document oriented NoSQL database. MongoDB supports journaling, datacentre-aware replication and auto-sharding to guarantee high availability. The database manages collections of BSON (a superset of JSON) documents. The major distinction between NoSQL and SQl is that NoSQL allows you to have fields which are multi-valued. The multiple values are represented as a JSON array.

MongoDB is a document oriented NoSQL database. MongoDB supports journaling, replication sets and auto-sharding to guarantee high availability. The database manages collections of BSON (a superset of JSON) documents.

The PHP driver for MongoDB is actively developed and maintained on Github. The PHP Language Center in the MongoDB documentation holds basic information about the driver.

Installation

The MongoDB PHP driver should work on nearly any system: Windows, Mac OS X, Unix, and Linux; little- and big-endian machines; 32- and 64-bit machines; PHP 5.2, 5.3, 5.4 and 5.5.

*nix

Run:

sudo pecl install mongo

Open your php.ini file and add to it:

extension=mongo.so

Windows

Download the extension from the list in the PHP manual and put it into the extension directory of your PHP install.

Add:

extension=php_mongo.dll

to your php.ini.

Useful Links

505 questions
67
votes
4 answers

Mongodb $push in nested array

I want add new data my nested array My document is: { "username": "erkin", "email": "erkin-07@hotmail.com", "password": "b", "playlists": [ { "_id": 58, "name": "asdsa", "date": "09-01-15", "musics": [ { …
balkondemiri
  • 933
  • 3
  • 11
  • 16
57
votes
5 answers

MongoDB and CodeIgniter

Can anyone assist in pointing me to a tutorial, library, etc. that will allow me to work with MongoDB from CodeIgniter?
IEnumerator
  • 2,960
  • 5
  • 31
  • 33
35
votes
4 answers

Mongodb php get id of new document?

Creating a document: $db->collection->insert($content); // $newDocID = ??? I'm trying to get the new document's id. How? Thanks.
Mark
  • 32,293
  • 33
  • 107
  • 137
31
votes
1 answer

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

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…
Behzadsh
  • 851
  • 1
  • 14
  • 30
30
votes
4 answers

Find a document with ObjectID in mongoDB

When I inserted some documents into a collection (without an ObjectID) mongoDB adds its own ObjectIDs. I want to query a document by its unique ObjectID. $db->collection_name->find(array('_id'=>'4e49fd8269fd873c0a000000'))); It does not work either…
jwchang
  • 10,584
  • 15
  • 58
  • 89
29
votes
5 answers

PHP+MongoDB: Uncaught exception 'MongoCursorException' with message 'No such file or directory'

I'm working on a web application which is trying to connect to a MongoDB database from PHP. In the 90% of page loads everything works fine, but in the other 10% it throws the following exception when I try to update a collection: Fatal error:…
Norbert
  • 302
  • 1
  • 9
  • 19
25
votes
2 answers

PHP Child class Magic __isset works but __get doesn't

I have an abstract parent class Mongo_Document (from mongodb-php-odm) and an inherited class Model_ActionPlan. Mongo_Document has magic __isset and __get methods that interact with an array inside the Mongo_Document class. I am trying to use the…
Moshe Katz
  • 15,992
  • 7
  • 69
  • 116
24
votes
5 answers

MongoDB - Aggregation - To get unique items in array

Here's my MongoDB collection: { "_id" : ObjectId("515d8f53175b8ecb053425c2"), "category" : "Batteries", "products" : [ { "brand" : "Duracell", "item" : [ "AA", "AAA" …
Ananth
  • 767
  • 1
  • 7
  • 15
22
votes
5 answers

Mongodb query specific month|year not date

How can I query a specific month in mongodb, not date range, I need month to make a list of customer birthday for current month. In SQL will be something like that: SELECT * FROM customer WHERE MONTH(bday)='09' Now I need to translate that in…
Lucas Serafim
  • 3,702
  • 6
  • 30
  • 36
15
votes
4 answers

How to convert MongoDB BSONDocument to valid JSON in PHP?

I am using MongoDB with the PHP Library. I inserted a valid JSON document inside MongoDB using PHP. I am now retrieving the document using findOne and am getting a MongoDB\Model\BSONDocument object as a result. How do I get back my JSON document…
sawrubh
  • 321
  • 1
  • 5
  • 14
13
votes
4 answers

MongoDB shell's db.stats() in php and python

I can see the statistics from Mongo shell as db.stats() or db.collection_name.stats() How do I view statistics of a database, or of a collection, from PHP and Python. EDIT: I have done it in PHP but still cant do it in Python. Help?
lovesh
  • 5,235
  • 9
  • 62
  • 93
12
votes
5 answers

How do you get the string value of a MongoID using PHP?

After doing an insert I want to pass the object to the client using json_encode(). The problem is, the _id value is not included. $widget = array('text' => 'Some text'); $this->mongo->db->insert($widget); If I echo $widget['_id'] the string value…
SomethingOn
  • 9,813
  • 17
  • 68
  • 107
12
votes
4 answers

How to set timeout to infinite to avoid MongoCursorTimeoutException in php

I am running the php script which fetch data from mongodb. I have a very huge database and I am getting this exception ..my mongodb version is 1.6.5 PHP Fatal error: Uncaught exception 'MongoCursorTimeoutException' with message 'cursor timed out…
Mark Gill
  • 3,721
  • 5
  • 22
  • 12
12
votes
1 answer

Aggregation $lookup with $let is not working

I have a collection TblStudent in mongodb like { "_id": ObjectId("5baa85041d7859f40d000029"), "Name": "John Doe", "RollNo": 12, "Class": "Ist" .... } I have another collection TblRoute like { …
12
votes
2 answers

Mongo Map Reduce first time

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…
James
  • 5,942
  • 15
  • 48
  • 72
1
2 3
33 34