0

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?

1 Answer 1

2

The inner function is async, the console log is being called prior to the function being run to completion.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.