私はphp用の新しいmongodbドライバに問題があります。 iterator_to_arrayは - > findに対して正常に動作しますが、1つのドキュメントのみを返すとMongoDB \ Model \ BSONDocument形式になります。これが唯一の配列に最初のレベル要素をオンにしますが、ネストされた文書要素がまだのMongoDB \モデル\ BSONDocumentままPHP mongodb findOneの結果を古い連想配列に変換しますか?
{
"_id" : ObjectId("3894713i4b13iu412"),
"active" : true,
"logo" : "this is logo",
"settings" : {
"email" : "days",
"testMode" : false
},
"stats" : {
"f" : {
"all" : [
{
"count" : NumberLong(15846),
"sum" : NumberLong(149479)
},
{
"count" : NumberLong(15846),
"sum" : NumberLong(148891)
},
{
"count" : NumberLong(15846),
"sum" : {
"1" : NumberLong(15522),
"2" : NumberLong(324)
}
}
]
},
"l" : {
"order" : ISODate("2016-12-05T09:10:53.855+0000"),
"feedback" : ISODate("2016-12-05T08:34:48.403+0000")
}
},
"title" : "hhh.ro",
"url" : "sdfasdf"
}
;:
$result = $db->clients->findOne(array('_id' => $id));
$result = (array) $result;
はモンゴでは、文書は、何かのように見えます
iterator_to_arrayは反復可能ではないため動作しません。
文書全体を古いmongoドライバやstdClassのような連想配列に変換するにはどうすればよいですか?
あなたはこのjson_decode(json_encode($結果)、true)を試すことができますすることができ、 – vijaykumar
これは_idのようになります["$ oid"] => string(24) "5784d428f079959a088b4595" –
この$ db-> clients-> findOne(配列( '_ id' => $ id)) - > toArray() – vijaykumar