These are chat archives for Automattic/mongoose

11th
Aug 2016
clocked0ne
@clocked0ne
Aug 11 2016 12:13
@antoine2vey you are returning from the function but because it is called as exec it already has completed the function, you need to make getBankAmount a callback itself
function getBankAmount(user, callback) {
ladderboardPlayer.findOne({name: user}).exec(function(err, doc) {
if(doc){
console.log(doc.bank) //returns 10000
callback (null, doc.bank); // null for error, doc.bank returns the data
}
});
}
call it as getBankAmount(user, function (err, bank){
// do things with your bank
});
sorry, formatted right:
clocked0ne
@clocked0ne
Aug 11 2016 12:18
function getBankAmount (user, callback){
    ladderboardPlayer.findOne({name: user}).exec(function (err, doc){
        if(doc){
            console.log(doc.bank)        //returns 10000
            callback(null, doc.bank);   // null for error, doc.bank returns the data
        }
    });
}
// call it as:
getBankAmount(user, function (err, bank){
    // do things with your `bank`
});
Andrei Demian
@unDemian
Aug 11 2016 13:12
hey, kinda dumb question is there a way to update a document's nested fields using an JSON object?
because with update I have to use selectors like 'field.innerField': value
or a quick way to convert a json object into a "flatten" version that would work with mongoose
repeale
@repeale
Aug 11 2016 18:56
Hi all,
Temperature_record.find( { timestamp: { $lt: new Date(), $gt: new Date(new Date().setDate(new Date().getDate() - 1)); } },
can someone give me some hint why i get an empty result?
when i store the record i simply use this code
timestamp: new Date(),
the query seems fine..and i have some record in the last day
thanks in advance :)
repeale
@repeale
Aug 11 2016 19:37
fixed with timestamp: { type : Date, default: Date.now },
;)