我使用的是Mongoose,Mongoose-paginate和ExpressJS。我有這樣的錯誤:Mongoose-paginate:溢出排序階段緩衝數據使用情況?
Error retrieving streams: MongoError: Runner error: Overflow sort stage buffered data usage of 34227161 bytes exceeds internal limit of 33554432 bytes
routes.js:
router.get("/", function(req, res, next) {
var page = req.query.page === undefined ? 1 : req.query.page;
var options = {
page: page,
limit: 30,
sort: {
created_at: 'desc'
}
};
// https://github.com/edwardhotchkiss/mongoose-paginate
Stream.paginate(query, options, function(err, result) {
if (err) {
console.log("Error retrieving streams: " + err);
errorMessage = "A problem occurred retrieving the streams";
return res.render("streams", {
streams: {},
errorMessage: errorMessage
});
}
return res.render("streams/list", {
streams: result.docs,
page: parseInt(result.page),
pages: parseInt(result.pages)
});
});
});
我該如何解決這個貓鼬數據限制問題?
編輯:
在此之後answer,我覺得在data
領域的規模過於龐大,所以我怎麼能指數data
場?
這是我的模型:
model.js:
var mongoose = require("mongoose");
var mongoosePaginate = require('mongoose-paginate');
// Declare schema
var streamSchema = new mongoose.Schema({
user_id: {
type: String,
required: true
},
title: {
type: String,
required: true
},
description: {
type: String,
required: true
},
hidden:{
type: String
},
data: {
type: Object
}
});
streamSchema.plugin(mongoosePaginate);
// Export schema
// Model.paginate()
mongoose.model("Stream", streamSchema);
我可以忽略的data
場時,我查詢流的名單?
編輯2:
有了這個解決方案:
db.mydb.ensureIndex({created_at: 1})
{
"createdCollectionAutomatically" : true,
"numIndexesBefore" : 1,
"numIndexesAfter" : 2,
"ok" : 1
}
我仍然得到同樣的錯誤...
編輯3:
找到了答案,排除字段:
var options = {
page: page,
limit: 30,
sort: {
created_at: 'desc'
},
select: '-data'
};
我仍然得到同樣的錯誤...
在這裏看到: HTTP: //stackoverflow.com/questions/27023622/overflow-sort-stage-buffered-data-usage-exceeds-internal-limit 您可以嘗試索引created_at字段。 – dyouberg
@dyouberg我已經看到了答案,但我怎樣才能'索引排序字段'? – laukok