让一个函数优先于Node.js中的另一个函数

I have a MongoClient function which seems to be asynchronous in nature. Followed by child process function which I am explicitly declaring as synchronous. The cp takes a parameter nextPort, and the value of nextPort is assigned inside MongoClient. Since cp.execSync takes precedence over MongoClient it doesn't take the new value of the variable rather the value it was declared with.

app.js

var nextPort=0; //Declaration 
MongoClient.connect(url1,{ useUnifiedTopology: true }, function(err, db) {
    if (err) throw err;
    var dbo = db.db("mydb");
    dbo.collection("mycol").distinct('port', function(err, result) {
      if (err) throw err;
      portArr=result;
      console.log(portArr.length);
      nextPort = portArr[portArr.length-1]+1; //New Value of nextPort
      console.log(nextPort);
      db.close();
    });
});

console.log('Container Created\n');
console.log(nextPort);
const result3 = cp.execSync('docker run -d -p '+nextPort+':27017 -v '+volumeLoc+' --name '+containerName+' mongo:'+version); 
//Taking the declaration value instead of new
console.log(result3.toString());

How do I execute MongoClient before cp.execSync. (Also, I'd really appreciate if the solution doesn't deal with promises)