【发布时间】:2017-01-18 18:32:41
【问题描述】:
我读了一个 Mongo 集合,我想获取最后一项的值。我做了一种从最旧到最新排序的方法(stackoverflow question),只取第一项,但我无法得到他的值。
这是我在集合中插入数据的代码:
'container.start': function(id) {
var ctn = docker.getContainer(id);
ctn.start(Meteor.bindEnvironment(function(err, data) {
if(err){
ErrorsContainer.upsert({
}, {
error: err
});
console.log(err);
}else{
console.log(data);
}
}));
}
然后是我读取集合的代码:
'click .start'(event) {
const idDB = this._id
const container = InfosContainers.findOne({_id: idDB});
const name = container["nameContainer"];
const idContainer = container["idContainer"];
console.log("the container: " + name + " is going to be started. His id is: " + idContainer);
Meteor.call("container.start",idContainer);
//get the last error
var error = ErrorsContainer.find({}, {sort: {_id: 1, limit: 1}});
if(error){
alert(error[error]); //tried error.error too
}
}
那么我怎样才能得到集合错误的值呢?
【问题讨论】:
-
{sort: {_id: 1, limit: 1}} 应该是 {sort: {_id: 1}, limit: 1}
-
问题是集合的错误是包含其他对象!所以看看我的答案
标签: javascript mongodb meteor