Note that there are some explanatory texts on larger screens.

plurals
  1. PODoctrine/MongoDB: Use key-value pairs instead numeric array
    primarykey
    data
    text
    <p>I'm using Doctrine ODM with MongoDB. I have a "product model" like this:</p> <pre><code>namespace Cms\Model; /** @Document(collection="products") */ class Product { /** @Id */ private $id; /** @String */ private $title; /** @String */ private $description; /** @Date */ private $createdAt; /** @EmbedMany(targetDocument="Cms\Model\ProductParam") */ private $params; /** @EmbedOne(targetDocument="Cms\Model\Coordinate") */ private $coordinate; public function __construct() { $this-&gt;details = new \Doctrine\Common\Collections\ArrayCollection(); $this-&gt;params = new \Doctrine\Common\Collections\ArrayCollection(); } } </code></pre> <p>My ProductParam model is like this:</p> <pre><code>namespace Cms\Model; /** @EmbeddedDocument */ class ProductParam { /** @String */ private $type; /** @String */ private $value; } </code></pre> <p>When i insert documents with this schema, the result is this:</p> <pre><code>{ "_id": ObjectId("4d17ac603ffcf6d01300002a"), "title": "Peugeot 206 2001-X-Reg, 1.4lx Air-con, 12 months mot, Credit Cards Accepted.", "description": "PEUGEOT 206 1.4LX IMMACULATE THROUGHOUT DRIVES ABSOLUTELY SUPERB", "params": { "0": { "type": "carBrand", "value": "PEUGEOT" }, "1": { "type": "carModel", "value": "206 LX" } } </code></pre> <p>But what i need is like this:</p> <pre><code>{ "_id": ObjectId("4d17ac603ffcf6d01300002a"), "title": "Peugeot 206 2001-X-Reg, 1.4lx Air-con, 12 months mot, Credit Cards Accepted.", "description": "PEUGEOT 206 1.4LX IMMACULATE THROUGHOUT DRIVES ABSOLUTELY SUPERB", "params": { carBrand: "PEUGEOT", carModel: "206 LX" } } </code></pre> <p>How can i do this? Thanks.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload