我正在使用synfony 2和mongoDB 我的收藏中有以下文件
{
"_id": {
"$oid": "577d40967e6ad1cc1b3c9869"
},
"type": "5520A",
"numserie": "9375031",
"desig": "CCCCC",
"const": "FFFF",
"code": "XXX/E/002",
"calis": [
{
"type": "TENSION CONTINUE",
"cali": [
{
"val": "330",
"unit": "mV"
}, {
"val": "3.3",
"unit": "V"
}]
},
{
"type": "Courant continu",
"cali": [{
"val": "330",
"unit": "µA"
}, {
"val": "3.3",
"unit": "mA"
}]
}]
}
在我的文档实体中,我使用了字段“calis”的集合注释:
/**
* @MongoDB\Field(type="collection")
*/
protected $calis;
当我在控制器中执行$list = $repository->findAll();
时
我获得字段“calis”([“calis”:protected] => NULL)的Null值,这不是空的!!
试图理解这个问题,我使用以下代码在存储库中创建了一个新方法:
public function getList() {
$m = new \MongoClient();
$db = $m->selectDB('mymngdb');
$collection = new \MongoCollection($db, 'Mycollec');
$cursor = $collection->find();
foreach ($cursor as $doc) {
echo '<pre>';
var_dump($doc);
echo '</pre>';
}
}
我正确地获取了所有字段 !!