与众不同

时间:2014-11-02 20:15:09

标签: mongoose

Mongoose有可能出现这样的情况吗?

User
    .findById(req.user)
    .populate({
        path: "x"})
    .populate({
        path: "messages",
        match: { to: req.user},
        select: "from date message"
        **distinct: "from"**
    })

    .exec (function(err, doc) {
    }

如果没有,我怎样才能获得在doc中没有重复“from”的消息?

1 个答案:

答案 0 :(得分:0)

我明白了:

User
    .findById(req.user)
    .populate({
        path: "x"
    })
    .populate({
        path: "messages",
        match: { to: req.user},
        select: "from date message"
    })
    .exec (function(err, doc) {

      Message.distinct("from",doc.messages,function(err, doc) {
      })