2015-05-06 42 views
0

我在MongoDB的這個疑問,但我想改變執行這些在PHP 我在MongoDB中也有點新的查詢,可你們好心告訴我 1.如何轉換的MongoDB到PHP

db.Station.group({ 
 
    "key": { 
 
     "OrganizationIdentifier": true 
 
    }, 
 
    "initial": { 
 
     "countstar": 0 
 
    }, 
 
    "reduce": function(obj, prev) { 
 
     if (true != null) if (true instanceof Array) prev.countstar += true.length; 
 
     else prev.countstar++; 
 
    }, 
 
    "cond": { 
 
     "OrganizationIdentifier": { 
 
      "$in": ["R10BUNKER", "USGS-CA"] 
 
     } 
 
    } 
 
});

2.

db.Station.find({ 
 
    "$or": [{ 
 
     "StateCode": 11 
 
    }, { 
 
     "CountyCode": 55 
 
    }] 
 
}, { 
 
    "MonitoringLocationIdentifier": 1, 
 
    "MonitoringLocationName": 1, 
 
    "MonitoringLocationDescriptionText": 1 
 
});

+0

這裏是在php中開始使用mongo的參考。 http://php.net/manual/en/mongo.tutorial.php – Kamran

+0

請告訴我們你到目前爲止所嘗試過的。 –

回答

1

php.net是你上手

MongoDB的一個很好的資源:http://php.net/manual/en/class.mongodb.php

MongoCollection ::找到

$projections = array(
    // your projections 
    // as in fields you want returned 
); 

$collection->find(array(
    '$or' => array(
     array('StateCode' => 11), 
     array('CountyCode' => 55), 
    ), 
), $projections); 

MongoCollection ::組

$keys = array(
    // your keys 
); 

$initial = array(
    'countstar' => 0, 
); 

$reduce = 'function(obj, prev) { 
    if (true != null) if (true instanceof Array) prev.countstar += true.length; 
    else prev.countstar++; 
}'; 

$options = array(
    'condition' => array(
     // your conditions 
    ), 
); 

$collection->group($keys, $initial, $reduce, $options);