2014-10-16 112 views
0

我想查询的集合,大约有200万项:猫鼬解析错误

var tagSchema = mongoose.Schema({ 
     tag: String, 
     book: mongoose.Schema.Types.ObjectId 
    }, { collection: 'tags' }); 

var Tag = mongoose.model('Tag', tagSchema); 

Tag.count({}, function(err, count){ 
    console.log("Number of tags:", count); 
}); 

Tag.find({}, function(err, count){ 
    console.log(count) 
    console.log(err) 
}).sort({'_id': 1}).limit(10); 

Tag.count返回预期的文件数目,但我正在逐渐尝试访问与'文件时出错找到”

错误仅仅是[错误:parseError发生]

任何想法?

回答

2

确保在执行之前将所有查询限制/排序/过滤器方法调用置于其中。

Tag.find({}).sort({'_id': 1}).limit(10).exec(function(err, tags) { 
    console.log(err, tags); 
}); 

在你的版本,因为您提供的回调find猫鼬立即运行查询和你的limitsort电话都来不及生效。

+0

完美的作品,正是我一直在寻找的。非常感激! – Silke 2014-10-16 18:55:09