MongoDB聚合未返回正确的日期

时间:2018-10-18 23:57:26

标签: mongodb aggregation-framework

我正在尝试从MongoDB(使用PHP)返回结果,其中具有以下输出: 用户名,探险次数,转录次数,最后转录日期

我使用的查询是

import React from 'react';
import { DB } from '../../backend/db';


export default class Home extends React.Component {

testCount() {
    DB.testCount();
}

render() {
    return (
        <div>
            Hello World!
            <button onClick={this.testCount}>
                Click me!
            </button>
            <CountView count={DB.getCount()}></CountView>
        </div>
    );
}
}

class CountView extends React.Component {
constructor(props){
    super(props);
    this.state = {
      count: DB.getCount()
    }
}

render() {
    return (
        <div>state:{this.state.count} props:{this.props.count}</div>
    );
}
}

除了最后一次约会,我得到的所有其他东西的回报都是正确的。它没有给我用户抄录的最后日期,而是给了我一些其他日期。不知道给出的日期,我只知道某些用户有更晚的日期。 想知道我在做什么错。

1 个答案:

答案 0 :(得分:0)

$min$maxlast_date一起使用

[
    '$group' => [
        '_id' => '$user_name',
        'transcriptionCount' => [
            '$sum' => 1
        ],
        'expedition' => [
            '$addToSet' => '$subject_expeditionId'
        ],
        'last_date' => [
            '$min' => '$classification_finished_at'
        ]
    ]
]
相关问题