After reading a Mongo collection, I am trying to retrieve the value of the last item. I have attempted to sort the collection from oldest to newest following this StackOverflow question, and then selecting only the first item, but I am unable to extract its value.
This snippet shows how data is inserted into the collection:
'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);
}
}));
}
Furthermore, here is the code used to read from the collection:
'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
}
}
Can someone guide me on how to correctly access the value of the error in the collection?