Logging within $db.get() function

I am needing help with the following code snippet:

$db.get(id).then (
          async function(data) {
          console.log('true')  
}
        function(error) {
          console.log(error + "error when retriving data from stored custom object data")
        });

I cannot get the ‘true’ to log to the console. It seems as the promise coming from the $db.set() function does not follow the async/ await process either as through testing when the data is stored into an item and/or returned the data will be console logged after other checkpoints in my code. I need some guidance on how to proceed with this.

Hey @Kiska_Sanchez,

If the data is stored, using the id you can retrieve with the below snippet -

$db.get(id).then (
        function(data) {
          console.log('true')
          console.log(data)
        }
        function(error) {
          console.log(error + "error when retriving data from stored custom object data")
        });

I noticed that you are defining the function in .then function as async, which need not be.

If you are using `async/await, use the below snippet.

let data = await $db.get(id)

Read more about KV store.
Hope this helps!

1 Like

Thank you!! I was putting the await in the wrong spot and that makes sooooooo much more sense :woman_facepalming: :melting_face:

This topic was automatically closed 6 days after the last reply. New replies are no longer allowed.