简体   繁体   中英

mongodb php multiple collections

A bit of weird issue - I am looking to enter data into two separate collections (same db) and I am getting totally weird results. I am sure it is the way I am doing this but it is the results which have me a bit baffled.

Here is a snippet of what I am trying to accomplish:

    $mynewconnection = new Mongo();                                 // create new mongo connection 
    $collectionDB                  = $mynewconnection->Datadb;         // select db 
    $collectionA                 = $collectionDB->DataA;                // select collectionA 
    $collectionB                 = $collectionDB->DataB;                // select collectionB 


    /* Go off and chop up data and create CriteriaA/B */ 

     $insertA        = $collectionA->insert($criteriaA); 
     $insertB        = $collectionB->insert($criteriaB); 

So what I am trying accomplish is to enter part of the data set into one collection and the other part of the dataset into another collection. What is happening is that sometimes the data will be entered into Both collections (as desired) and other times data will be entered into just collectionA and yet other times data will be entered into just collectionB.

Anyone have any ideas on what I am missing or what would be causing this strange behavior?

When you fire a query to write something to MongoDB, it does not confirm whether the data is written to database or not. You need to see the page of php's manual for Write Concerns.

The link for the same is: http://www.php.net/manual/en/mongo.writeconcerns.php

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM