小编M.Z*_*.Z.的帖子

mongo db 聚合随机化(随机播放)结果

我正在浏览一堆 mongo 文档,但找不到洗牌或随机化结果内容的可能性

有没有 ?

shuffle mapreduce mongodb aggregation-framework

5
推荐指数
1
解决办法
6086
查看次数

使用php进行mongodb日期聚合操作员时区调整

我正在尝试使用日期聚合运算符调整时区.我需要在$signs.timestamp场上进行-7小时的调整.

这是我的代码:

function statsSignatures() {
    $cursor = $this->db->collection->users->aggregate(
        array('$unwind' => '$signs'),
        array('$project'=>array(
            'signs'=>'$signs',
            'y'=>array('$year'=>'$signs.timestamp'),
            'm'=>array('$month'=>'$signs.timestamp'),
            'd'=>array('$dayOfMonth'=>'$signs.timestamp'),
            'h'=>array('$hour'=>'$signs.timestamp')
        )),
        array('$group'=>array(
            '_id'=>array('year'=>'$y','month'=>'$m','day'=>'$d','hour'=>'$h'),
            'total'=>array('$sum'=>1)
        )),
        array('$sort'=>array(
            '_id.year'=>1,
            '_id.month'=>1,
            '_id.day'=>1,
            '_id.hour'=>1
        ))
    );
    return $cursor['result'];
}
Run Code Online (Sandbox Code Playgroud)

我正在使用MongoDB版本2.6.3.

非常感谢 !

php timezone date mongodb aggregation-framework

3
推荐指数
1
解决办法
2237
查看次数

在 Symfony 3.2 中将 json 反序列化为嵌入对象 - 给出了“Acme\StoreBundle\Document\Gps”类型的预期参数,“array”

Acme\StoreBundle\Document\Person

/**
 * @MongoDB\Document
 */

class Person
{

/**
 * @MongoDB\bool
 */

private $hasemail;

/**
 * @MongoDB\EmbedOne(targetDocument="Gps")
 */

private $gps;

/**
 * @MongoDB\Field(name="email", type="collection")
 */

private $email;

}
...
Run Code Online (Sandbox Code Playgroud)

Acme\StoreBundle\Document\Gps

/**
 * @MongoDB\EmbeddedDocument
 */

class Gps
{

/**
 * @MongoDB\Field(type="float")
 */

private $latitude;


/**
 * @MongoDB\Field(type="float")
 */
private $longitude;

}
...
Run Code Online (Sandbox Code Playgroud)

mongo json 文档

{
"hasemail": true,
"gps": {
    "latitude": 42.941579990394,
    "longitude": -85.244641161525
},
"email": [
    "sdfgsdfg@sfgsdfg.org",
    "sdfgsdfg@fgsdfg.com",
    "sdfgsdfg@sdfgsdfg.com"
]
}
Run Code Online (Sandbox Code Playgroud)

将 mongo 文档序列化为 json 工作完美。但是将 json 反序列化为文档会引发错误:“给出了类型为 'Acme\StoreBundle\Document\Gps'、'array' 的预期参数” …

serialization symfony

2
推荐指数
1
解决办法
2014
查看次数