Search code examples
javascriptarraysjsonfaunadb

How to retrieve document ID from faunaDb query


I have this array

[ Ref(Collection("twitch_users"), "280881231730573837") ]

And i wish to retrive the string of numbers and use them for another function in my code, however I'm unsure how I can do this as I'm used to doing something like data.info[0] but the object doesn't have a name and I'm not sure how to achieve something like that without using a name.

This may be a little hard to reproduce as the data is being retrieved from an external database but i'll do my best to provide whats needed

// These first two lines return
// [ Ref(Collection("twitch_users"), "280881231730573837") ]
// Please note Ref() is from the FaunaDB API and not a function in my code



var queryuserInfo = fauna.paginate(q.Match(q.Index("users.allInfo"), tags.username));
queryuserInfo.each(function (page) { userInfo = page });

I then console.log

console.log(userInfo[0])

Solution

  • It is the Ref ID generated by FaunaDB. You can use the id attribute to retrieve the ID.

    console.log(userInfo[0].id)