Easy data visualization

New user here! I’m loving Fauna, but I have a question:

What would be the best way to make simple queries and export the data (for visualization)?

For instance, I have a User collection; each User has a balance. I’d like to Fetch all Users, ordered by balance DESC.

The online shell looks like an option, however I couldn’t find any resource on how to use it (how do I form actual queries!)

Am I in the right direction?


In other words, I just need to explore my data: How do I do that? It’s urgent! :scream:

Another question is: Faune console is great, but how do I display more than 100 records !!?

To improve performance, only 100 results are shown.

Using Fauna data manager, I’m getting the following error while trying to export:

ERROR insufficient privilages to read all roles.

I’m using the same secret I use to push/fetch data to/from the database. How can I create a secret with enough privileges?

I added a new key with Admin instead of Server role. It appears to have removed the error but simple unable to export data to json.

Sending queries to FaunaDB to get results

There are three options to send queries to FaunaDB:

  • the dashboard UI (as you’ve discovered)
  • the Fauna shell (send queries via terminal)
  • language drivers (send queries via JavaScript/Go/C# etc…)

In your case I would just use a language driver and write a small script.

Learning FQL

The rest comes down to learning FQL which will initially be a bit more verbose than what you are used o since FQL is made to support a wide range of use-cases and at the same time is made to be easily generated.

If you are coming from SQL this might help:

Or read the section: ‘Retrieving data’ here: https://css-tricks.com/rethinking-twitter-as-a-serverless-app/

Or the Crud tutorial here: https://docs.fauna.com/fauna/current/cookbook/

We have a full 5 series FQL post coming in but that will be too late since it appears urgent.

Data manager:

You indeed need an admin role for that but it’s not clear what is not working when you say: “simply unable to export data to json”, is the format not what you desire? (tbh I never used the data manager myself though, not sure whether I can help)

1 Like

Do you know if it’s possible to browse data from the Dashboard UI as a quick solution (I’ll get more in depth later on how to export and view properly.)?

Right now, I’m only able to show the first 100 records of each collection! Is there any way to show records 101-200, etc?

Well if all you want is export the data. Throw this in the shell at dashboard.fauna.com (of course choose your collection, I used my ‘fweets’ collection.

  Lambda(['f'], Get(Var('f')))

And then you can start playing with the paginate parameter.

    Documents(Collection('fweets')), {size: 2}
  Lambda(['f'], Get(Var('f')))

Since there I’m not returning everything I get an after parameter:

If I copy in that after parameter I get the next result:

    Documents(Collection('fweets')), {size: 2, after:  [Ref(Collection("fweets"), "268431420759736839")]}
  Lambda(['f'], Get(Var('f')))

Which then returns an after and before parameter so I can get the next page again by continuing like that and paste the after in again.

Page size is here set to 2 by me as an example. Largest page size is 100000. Of course throwing that in a dashboard that shows these visually is not going to work, that’s why I told you to write a script and just throw in this query and write it to JSON :).

1 Like

Thanks for your help @databrecht.

I am now falling back to this solution and making a quick dashboard for myself (using javascript):

What should I go for among all those functions if I want to make a query to:

  • get all records from a certain collection
  • get all records from a certain collection ordered by one of the fields
  • get all records matching a specific filter (and possibly ordered by one of the fields)

Thanks again!

Get all records: see above, I already threw you that query:

Ordered by a certain collection: the values in an index determine the ordering, Create an index, use ‘Match’ to query that index, so you are looking for ‘Index’ and ‘Match’ to read up on. You’ll need to either put all values in the index (values are also the return values of an index) or only the ones you order on + the reference. In the latter case, use Map/Get (another two functions for you to read up on) to go from an array of references to the result.

Note that if you do choose to put a lot of values in an index that indexes are like views, the data will be duplicated.

get all records matching a specific filter: make an index with the ‘terms’ you want to filter on. use Match to filter. There are examples in our docs. If you need to filter on numbers (bigger than etc) you are looking for the ‘Range’ function, which requires you to place the attributes you want to filter on in the values. If you are looking for advanced range filters (on multiple values, read this: https://stackoverflow.com/questions/61509089/how-to-query-by-multiple-conditions-in-faunadb/61581648#comment108980541_61581648) , there are multiple options.

I’m sorry, I can’t just start writing examples for each possible query you might want, you’ll have to read through these.

Resources you should check out:

You will of course also need functions like:

1 Like

And as pointed out before:

This has quite some examples that answer your questions :slight_smile:

Thanks! I’ll take a look at all this and report here.

I often use Forest Admin to create a quick Admin panel with my data. However, I need to allow direct access to my database for that. Is this compatible with Fauna?

1 Like

Thanks a lot, I achieved exactly what I want! This page was most useful for me:

1 Like