How can I store an array with Doctrine and Mongo DB?
I do not want reference document, only array.
Example:
Type[
Type1,
Type2,
You can use mongo types hash or collection as your need.
Hash : Stores and retrieves the value as associative array.
Collection : Stores and retrieves the value as numeric indexed array.
For example:
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;
}
The data is stored such as :
"tags": [
"man",
"boy",
"male",
"sandal",
"cloth",
"army boots",
"boots",
"sport shoes",
"school",
"casual",
"office"
],
"country_wise_total_count": {
"NP": NumberInt(7),
"US" : NumberInt(10)
}