My model:
var CategorySchema = new mongoose.Schema({
...
...
...
, sortId: Number
...
})
my code:
var ca = 0
Category.findOne({orgId: user.orgId}).desc('sortId').run(function(err, cat){
if(cat != null){
ca = cat.sortId + 1
}
})
console.log(ca)
“ca” keep being 0, even though that it find a record where sortId is 1. Any who can see what I’m doing wrong?
The inner function is async, the console log is being called prior to the function being run to completion.