You can filter by user
, sort by created
descending, and then skip the first doc:
MyModel.find({user: '52ecdb4ea6b03a94179612de'}).sort('-created').skip(1)
.exec(function(err, docs) { ... });
Pergunta
How to query all documents of user "52ecdb4ea6b03a94179612de" exclude the latest docucment (document with "article":"aa", "created": ISODate("2014-02-01T13:03:47.577Z") in this case)?
{
"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"),
}
Solução
You can filter by user
, sort by created
descending, and then skip the first doc:
MyModel.find({user: '52ecdb4ea6b03a94179612de'}).sort('-created').skip(1)
.exec(function(err, docs) { ... });