如何查询所有文档根据时间排除最新文档

时间:2014-02-03 15:41:48

标签: mongoose document

如何查询用户“52ecdb4ea6b03a94179612de”的所有文件,排除最新文件(带有“文章”:“aa”,“已创建”的文件:ISODate(“2014-02-01T13:03:47.577Z”) )?

{
  "article":"aa",
  "user": ObjectId("52ecdb4ea6b03a94179612de"),
  "comment": "222222222",
  "created": ISODate("2014-02-01T13:03:47.577Z"),

},
{
  "article": "bb",
  "user": ObjectId("52ecdb4ea6b03a94179612de"),
  "comment": "222222222",
  "created": ISODate("2014-01-01T13:03:47.577Z"),

},
{
  "article": "cc",
  "user": ObjectId("52ecdb4ea6b03a94179612de"),
  "comment": "222222222",
  "created": ISODate("2013-01-01T13:03:47.577Z"),

}

1 个答案:

答案 0 :(得分:0)

您可以按user进行过滤,按created降序排序,然后跳过第一个文档:

MyModel.find({user: '52ecdb4ea6b03a94179612de'}).sort('-created').skip(1)
    .exec(function(err, docs) { ... });