我正在嘗試搜索對特定數據項進行過濾的MongoDB數據庫。具體來說,我希望USA = PG-13適合我的過濾器。如何搜索按特定值過濾的MongoDB數據庫
如何提出請求:獲取電影,其中美國的MPAA = PG-13?
收集國家:
{
"_id": ObjectId("4fd79ec34c9fda9d05000080"),
"en": "USA"
}
{
"_id": ObjectId("4fd79ec34c9fda9d0500007f"),
"en": "Hong Kong"
}
收集電影:
{
"_id": ObjectId("4fd79ec34c9fda9d05000081"),
"movieId": {
"imdb": "0848228"
},
"movieTitle": "The Avengers",
"movieYearSpan": {
"start": "2012",
"end": "2012"
},
"movieType": "Movie",
"movieMpaa": {
"verdict": "Rated PG-13",
"0": {
"mpaa": "IIA",
"country": ObjectId("4fd79ec34c9fda9d0500007f")
},
"1": {
"mpaa": "PG-13",
"country": ObjectId("4fd79ec34c9fda9d05000080")
}
}
}
我想首先得到美國的ID。
$cursorCountry = $collectionCountry->find(array("en" => "USA"));
$idCountry = $cursorCountry->getNext();
$_id = $idCountry["_id"];
$cursorMovie = $collectionMovie->find(array("movieMpaa.country" => $_id, "movieMpaa.mpaa" => "PG-13"));
不工作! 那麼如何提出請求? 要獲得電影,其中美國MPAA = PG-13?
'$ _id = new MongoId($ _ id)'help?無論如何,我會改變數據庫@Gates VP的建議。 – Matthew