Query your Database
Using the web console (opens in a new tab), you can execute any queries in the bottom terminal:
When using the console's terminal, do not insert spaces in objects. Spaces are used to separate arguments so it will be parsed incorrectly, or wrap the object with '
or "
.
Get Info
To get general information about your database:
getInfo
Add
To add a doc to a collection. The doc ID will be auto-generated:
# add : data_JSON : collection_name
add {name:"Bob",age:20} people
Set
To write a new document:
# set : data_JSON : collection_name : doc_id
set {name:"Bob",age:20} people Bob
Update
To update an existing document:
# update : data_JSON : collection_name : doc_id
update {age:30} people Bob
Delete
To delete an existing document:
# delete : collection_name : doc_id
delete people Bob
Upsert
To update an existing document or create a new one if it does not already exist:
# upsert : data_JSON : collection_name : doc_id
upsert {name:"Bob",age:20} people Bob
Let's add some new documents for the following tutorial:
set {name:"Bob",age:20} people Bob
set {name:"Alice",age:30} people Alice
set {name:"Mike",age:40} people Mike
Get
To get a single doc:
get people Bob
To get all the docs in a collection:
get people
Limit
To limit the number of the docs returned:
get people 2
Where
To get the docs where the age is 20:
get people ["age","==",20]
You can use the same operators as Firestore (opens in a new tab), which includes ==
, !=
, >
, >=
, <
, <=
, in
, not-in
, array-contains
, and array-contains-any
.
Sort
To sort by age in descending order:
get people ["age","desc"]
Single field indexes are automatically generated. But to sort by more than 1 field, multi-field indexes need to be added explicitly. Read onto the following section.
Add multi-field indexes
To set an index to sort people first by age in descending order, then by name in ascending order:
addIndex [["age","desc"],["name","asc"]] people
Then you can use this query:
get people ["age","desc"] ["name"]