Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/mongodb/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mongodb 条令ODM:嵌入多个GridFS文档异常_Mongodb_Symfony_Doctrine Orm_Gridfs - Fatal编程技术网

Mongodb 条令ODM:嵌入多个GridFS文档异常

Mongodb 条令ODM:嵌入多个GridFS文档异常,mongodb,symfony,doctrine-orm,gridfs,Mongodb,Symfony,Doctrine Orm,Gridfs,我试图通过Doctrine/Symfony 2在GridFS中的主大图中嵌入一个缩略图 主要图像文档如下所示: <?php namespace namespace\goes\here\Document; use Doctrine\ODM\MongoDB\Mapping\Annotations as MongoDB; /** * @MongoDB\Document */ class FullSizeImage { /** @MongoDB\Id */ priva

我试图通过Doctrine/Symfony 2在GridFS中的主大图中嵌入一个缩略图

主要图像文档如下所示:

<?php 

namespace namespace\goes\here\Document;

use Doctrine\ODM\MongoDB\Mapping\Annotations as MongoDB;

/**
 * @MongoDB\Document
 */
class FullSizeImage
{

    /** @MongoDB\Id */
    private $id;

    /** @MongoDB\File */
    private $file;

    /** @MongoDB\String */
    private $filename;

    /** @MongoDB\String */
    private $mimeType;

    /** @MongoDB\Date */
    private $uploadDate;

    /** @MongoDB\Int */
    private $userId;

    /** @MongoDB\Int */
    private $length;

    /** @MongoDB\Int */
    private $chunkSize;

    /** @MongoDB\String */
    private $md5;

    /** @MongoDB\Collection */
    private $tags = array();

    /** @MongoDB\EmbedOne(targetDocument="Thumbnail") */
    private $thumbnail;

    public function getId()
    {
        return $this->id;
    }

    public function setId($id)
    {
        $this->id = $id;
    }

    public function getTags()
    {
        return $this->tags;
    }

    public function setTags($tags)
    {
        $this->tags = $tags;
    }

    public function getFile()
    {
        return $this->file;
    }

    public function setFile($file)
    {
        $this->file = $file;
    }

    public function getFilename()
    {
        return $this->filename;
    }

    public function setFilename($filename)
    {
        $this->filename = $filename;
    }

    public function getMimeType()
    {
        return $this->mimeType;
    }

    public function setMimeType($mimeType)
    {
        $this->mimeType = $mimeType;
    }

    public function getChunkSize()
    {
        return $this->chunkSize;
    }

    public function getLength()
    {
        return $this->length;
    }

    public function getMd5()
    {
        return $this->md5;
    }

    public function getUploadDate()
    {
        return $this->uploadDate;
    }

    public function getUserId()
    {
        return $this->userId;
    }

    public function setUserId($userId)
    {
        $this->userId = $userId;
    }

    public function getThumbnail()
    {
        return $this->thumbnail;
    }

    public function setThumbnail($thumbnail)
    {
        $this->thumbnail = $thumbnail;
    }

}
<?php

namespace namespace\goes\here\Document;

use Doctrine\ODM\MongoDB\Mapping\Annotations as MongoDB;

/** @MongoDB\EmbeddedDocument */
class Thumbnail
{

    /** @MongoDB\Id */
    private $id;

    /** @MongoDB\File */
    private $file;

    /** @MongoDB\String */
    private $filename;

    /** @MongoDB\String */
    private $mimeType;

    /** @MongoDB\Date */
    private $uploadDate;

    /** @MongoDB\Int */
    private $length;

    /** @MongoDB\Int */
    private $chunkSize;

    /** @MongoDB\String */
    private $md5;

    public function getId()
    {
        return $this->id;
    }

    public function setId($id)
    {
        $this->id = $id;
    }

    public function getFile()
    {
        return $this->file;
    }

    public function setFile($file)
    {
        $this->file = $file;
    }

    public function getFilename()
    {
        return $this->filename;
    }

    public function setFilename($filename)
    {
        $this->filename = $filename;
    }

    public function getMimeType()
    {
        return $this->mimeType;
    }

    public function setMimeType($mimeType)
    {
        $this->mimeType = $mimeType;
    }

    public function getChunkSize()
    {
        return $this->chunkSize;
    }

    public function getLength()
    {
        return $this->length;
    }

    public function getMd5()
    {
        return $this->md5;
    }

    public function getUploadDate()
    {
        return $this->uploadDate;
    }

}
我遇到这个例外,

无法存储文件:不允许使用零长度密钥,您使用了吗$ 用双引号


我错过什么了吗?或者是否有更好的方法将这些图像及其关系存储在mongo中?

字段,其中GridFS必须是最顶层的文档。它可以被其他文档引用,但不能被任何其他文档嵌入。这是因为在Mongo ODM中实现了GridFS

不久前我也遇到过类似的问题。我最终得到了上述解决方案

更多详情:

$thumbnail = new Thumbnail();
$thumbnail->setFile($thumbPath);
$thumbnail->setFilename($thumbName);
$thumbnail->setMimeType($thumbMimeType);
$thumbnail->setUserId($user->getId());

$fsi = new FullSizeImage();
$fsi->setFile($file->getRealPath());
$fsi->setTags(array('tag', 'tag', 'tag'));
$fsi->setFilename($file->getFilename());
$fsi->setMimeType($file->getMimeType());
$fsi->setUserId($user->getId());
$fsi->setThumbnail($thumbnail);

$dm->persist($fsi);
$dm->flush();