use*_*256 5 doctrine mongodb symfony
如何使用Doctrine和Mongo DB存储数组?
我不想要参考文档,只有数组.
例:
Type[
Type1,
Type2,
Type3
]
Run Code Online (Sandbox Code Playgroud)
我是否需要创建新的Doctrine ODM数据类型?
您可以根据需要使用mongo类型哈希或集合.
散列:将值存储并检索为关联数组.
集合:将值存储并检索为数字索引数组.
例如:
use Doctrine\ODM\MongoDB\Mapping\Annotations as MongoDB;
class Category
{
/**
* @MongoDB\Field(name="tags", type="collection")
*/
private $tags;
/**
* @MongoDB\Field(name="country_wise_total_count", type="hash")
*/
private $country_wise_total_count;
}
Run Code Online (Sandbox Code Playgroud)
数据存储如下:
"tags": [
"man",
"boy",
"male",
"sandal",
"cloth",
"army boots",
"boots",
"sport shoes",
"school",
"casual",
"office"
],
"country_wise_total_count": {
"NP": NumberInt(7),
"US" : NumberInt(10)
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
12327 次 |
| 最近记录: |