mongoosesorting

我有sorting显示数据的问题。 这是我的查询,

Activity.find({"user_id": sesUser._id}, {}, {offset: 0, limit : 5, sort:{createdAt:1}}, function (e,a){ ... }); 

我有关于252长度的数据,而我的最新数据是2015年6月9日。如果我使用这个查询,我只从2015年6月5日/上周数据获取数据,而不是获取最新数据,但是如果我不使用sorting,出现。

我已经使用下面的查询,但结果是一样的。

 Activity.find({"user_id" : sesUser._id}).sort("createdAt").exec(function(err,a){ ... }); 

任何帮助? 我正在使用Mongoose v3

– 编辑 – 这是我的活动架构/模型

 var mongoose = require('mongoose'); var Activity = mongoose.Schema({ sender_id : {type: String, required: true }, user_id : {type: String, required: true }, product_id : {type: String, default : "" }, type : {type: String, required: true }, createdAt : {type: String, default : new Date()} }); module.exports = mongoose.model('Activity', Activity); 

 `createdAt : {type: Date, default : new Date()}` 

typesdate不是string人

它会自动创buildcreatedAt和updatedAt

 var options={ timestamps: true } var Activity = mongoose.Schema({ sender_id : {type: String, required: true }, user_id : {type: String, required: true }, product_id : {type: String, default : "" }, type : {type: String, required: true } },options);