Everytime adding a new data or updating existing data, new_data and updated_data variables will get increment. But when I try to console log the total count's (new_data and updated_data) at the bottom of the code the result is 0. How do we address this in Node using async ?
Code
let new_data = 0
let updated_data = 0
let vehicles = _.each(results.data, function (value, key) {
    let condition = { VIN: value.VIN }
    Vehicle.model.findOne(condition, function (err, doc) {
        if (doc) {
            let condition2 = { VIN: doc.VIN }
            Vehicle.model.update(condition2, value, function (err, doc1) {
                updated_data += 1
                if (doc && typeof doc.log === 'function') {
                    const data = {
                        action: 'Update',
                        category: 'Inventory Import',
                        message: 'Import Successful',
                        status: '200'
                    }
                    return doc.log(data); 
                }
            })
        } else {
            Vehicle.model.create(value, function (err, doc2) {
                new_data += 1
                if (doc2 && typeof doc2.log === 'function') {
                    const data = {
                        action: 'Create',
                        category: 'Inventory Import',
                        message: 'Import Successful',
                        status: '200'
                    }
                    return doc2.log(data);
                }
            })
        }
    })
})
console.log("new datad : ", new_data)
console.log("updated_data : ", updated_data)
 
     
    