Since you are requesting an asynchronous resource you need to handle it in the same way, it is not possible for the promise to run synchronously, that is why I propose a solution to the problem:
It is likely that many more changes in the code will be needed for the following to work correctly, I only intend to show how the process should be done.
var getData = function (id) {
return new Promise(function (resolve, reject) {
db.collection('users').doc(id).get()
.then(function (doc) {
if (doc.exists) {
resolve(doc.data());
}
reject('Document not found');
})
.catch(function (exception) {
reject(exception);
})
});
}
var id = 6;
getData(id).then(function (data) {
console.log('Datos:', data);
// Proceso a realizar
}).catch(function (exception) {
console.error('Exeption:', exception);
});
Documentation of the Promises