faunadb

How to get nested documents in FaunaDB?

泪湿孤枕 提交于 2021-02-20 18:56:44
问题 To get a single document in Fauna we do: q.Get(q.Ref(q.Collection('posts'), '192903209792046592')) And we get something like: { data: { title: 'Lorem ipsum', authorId: '892943607792046595' } } Is it possible to instead get the post and the author in the same query? Something like this: { data: { title: 'Lorem ipsum', author: { name: 'John Doe' } } } 回答1: Since this is a common question I'm going to expand it and give you all info that you should need to get started. I recently wrote an

How to query by multiple conditions in faunadb?

半腔热情 提交于 2021-01-20 18:43:48
问题 I try to improve my understanding of FaunaDB. I have a collection that contains records like: { "ref": Ref(Collection("regions"), "261442015390073344"), "ts": 1587576285055000, "data": { "name": "italy", "attributes": { "amenities": { "camping": 1, "swimming": 7, "hiking": 3, "culture": 7, "nightlife": 10, "budget": 6 } } } } I would like to query in a flexible way by different attributes like: data.attributes.amenities.camping > 5 data.attributes.amenities.camping > 5 AND data.attributes

How to query by multiple conditions in faunadb?

对着背影说爱祢 提交于 2021-01-20 18:43:14
问题 I try to improve my understanding of FaunaDB. I have a collection that contains records like: { "ref": Ref(Collection("regions"), "261442015390073344"), "ts": 1587576285055000, "data": { "name": "italy", "attributes": { "amenities": { "camping": 1, "swimming": 7, "hiking": 3, "culture": 7, "nightlife": 10, "budget": 6 } } } } I would like to query in a flexible way by different attributes like: data.attributes.amenities.camping > 5 data.attributes.amenities.camping > 5 AND data.attributes

How do I create an index in Fauna DB that returns sorted data in key value pairs

佐手、 提交于 2020-12-26 05:04:48
问题 I’m trying to create an index that returns sorted data in an object with keys. The default index for my collection returns something like this: { "ref": Ref(Collection("posts"), "251333584234742292"), "ts": 1583632773120000, "data": { "title": "A Great Title", "sort_date": "2019-12-11", "post_type": "blog", "status": "published", } },... I created an index in the shell with this code: CreateIndex({ name: "posts_sort_date_desc", source: Collection("posts"), values: [ { field: ["data", "sort

How to get documents that contain sub-string in FaunaDB

…衆ロ難τιáo~ 提交于 2020-08-04 10:53:20
问题 I'm trying to retrieve all the tasks documents that have the string first in their name. I currently have the following code, but it only works if I pass the exact name: res, err := db.client.Query( f.Map( f.Paginate(f.MatchTerm(f.Index("tasks_by_name"), "My first task")), f.Lambda("ref", f.Get(f.Var("ref"))), ), ) I think I can use ContainsStr() somewhere, but I don't know how to use it in my query. Also, is there a way to do it without using Filter() ? I ask because it seems like it filters

How to get documents that contain sub-string in FaunaDB

我与影子孤独终老i 提交于 2020-08-04 10:50:34
问题 I'm trying to retrieve all the tasks documents that have the string first in their name. I currently have the following code, but it only works if I pass the exact name: res, err := db.client.Query( f.Map( f.Paginate(f.MatchTerm(f.Index("tasks_by_name"), "My first task")), f.Lambda("ref", f.Get(f.Var("ref"))), ), ) I think I can use ContainsStr() somewhere, but I don't know how to use it in my query. Also, is there a way to do it without using Filter() ? I ask because it seems like it filters

In react check if page has refreshed then set localstorage off of graphql query otherwise keep current local storage for state

寵の児 提交于 2020-05-17 07:08:04
问题 I am attempting to build a hit counter that is based off of a user click. It increments the counter each time the user clicks. I am running GatsbyJS with react. I am using a lambda function to store the count in faunadb, so it increments each time the button is clicked. This is working. For the client side I am updating the state of the component hitCounter number by using localStorage, so each time the button is clicked I update localStorage. All of this works pretty well. However if I