猫鼬排序

Bag*_*oso 5 mongoose mongodb node.js

我在使用排序显示数据时遇到问题.这是我的查询,

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

我有关于252长度的数据,我的最新数据是2015年6月9日.如果我使用此查询我只从2015年6月5日/上周数据获得数据而不是获取最新数据,但如果我不使用排序,则最新数据出现了.

我在下面使用过这个查询但结果却是一样的.

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

有帮助吗?我正在使用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);
Run Code Online (Sandbox Code Playgroud)

kax*_*993 4

`createdAt : {type: Date, default : new Date()}`
Run Code Online (Sandbox Code Playgroud)

输入日期而不是字符串 man