【发布时间】:2015-10-15 06:55:50
【问题描述】:
我正在尝试将不同的项目插入到 MongoDB 集合中,但我希望将项目插入到数组的顶部,以便在检索集合项目时对它们进行排序。
我正在使用此代码:
var json = { title : title, postid : postid, image : image, decription : description};
collection.insert(json, function (err, result) {
if (err) {
console.log(err);
} else {
console.log('Here we go', result.length, result);
}
});
这个代码来检索集合项目:
collection.find().toArray(function (err, result) {
if (err) {
console.log(err);
} else if (result.length) {
first_item = result[0].postid;
console.log('Found:',first_item);
} else {
}
db.close();
});
}
});
我每 10 分钟插入一次新项目,当我检索项目时,我希望最后插入的项目位于位置 0
【问题讨论】:
标签: javascript node.js mongodb