2014-10-16 131 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