I have setup MongoDB on my Mac and use PHP to deal with it. I installed the PHP driver for Mongo and successfully connect and insert and select from the database.
The problem I am facing is that when I paste in Mongo, I see 2 copies of the document, although I only called the paste function once.
Here is the php code:
<?php $mongoDB = new Mongo(); $db = $mongoDB->blog; $collection = $db->posts; $document = array( "title" => "cat with a hat", "body" => "once upon a time a cat with a hat ..."); $collection->insert($document);
Result in db:
> db.posts.find() { "_id" : ObjectId("5089ff5aaa3479c97300000f"), "title" : "cat with a hat", "body" : "once upon a time a cat with a hat ..." } { "_id" : ObjectId("5089ff5aaa3479c973000011"), "title" : "cat with a hat", "body" : "once upon a time a cat with a hat ..." }
I'm not sure if this is a problem with the PHP driver, Mongo, Apache or my OS. I used Brew to install Mongo and PECL to install the mongo driver (pecl install mongo).
Why do I have 2 copies when pasted into Mongo?
edit: typo in php code fixed. Thanks bcmcfc
source share