0

The below code is not returning a value back but it console logs out fine. Any ideas how I can set the value of X?

  var dbSize = dbo.collection('Items').count()
        var x = 0
        x = dbSize.then(len =>  {
            return len
        })

This is what is being logged 'Promise { }' however if I simply write this:

 dbo.collection('Items').count()
            var x = 0
            dbSize.then(len => {
                console.log(len)
            })

then It logs out fine.

Georgef3615
  • 9
  • 1
  • 2
  • Indeed, a Promise does not return a value. It returns a promise to resolve a value, that you get with the `then`. So what is the question again? – Keith Mar 02 '18 at 16:54

1 Answers1

0

you can warp your code with an async function and then use await to make your code work like synchronized code

 
 const a = async () =>{
 var dbSize = await dbo.collection('Items').count()
 console.log(dbSize)
}

a();
Amit Wagner
  • 3,134
  • 3
  • 19
  • 35