问题标签 [faunadb]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
0 回答
126 浏览

javascript - 除非页面刷新,否则带有 gatsby js 的 FaunaDB 客户端 graphql 不会重新呈现

我正在使用本教程https://css-tricks.com/build-a-dynamic-jamstack-app-with-gatsbyjs-and-faunadb/作为指南,使用 zoodb 和 gatsbyjs 进行一些动态内容更新。现在我的一切都在某种程度上发挥了作用。我遇到的问题是,如果我手动更新数据库,或者最终在 lambda 函数中更新,我希望 graphql 查询导致状态更改并重新渲染反应。发生的情况是我只能在页面刷新时看到新数据。根据这篇文章,这应该是客户端水合,但是当数据库发生变化时,我没有得到预期的效果。

任何帮助将不胜感激

这是我的盖茨比页面

在 gatsbybrowser.js 我正在执行以下操作

0 投票
2 回答
270 浏览

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

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 change the state of StoryPopFull (seen in code below) by clicking the close button in StoryBlock and reopen by clicking the more button the state keeps the localStorage state which is good. However If I change the state of StoryPop closing the StoryGrid reopen everything the state of SvgAnimation(component where the hit counter lives) is taking it from the graphQL query, now this would be fine if the query came fast enough, but there is about a 20 second delay between the lambda, faunadb and hitting refresh on the page, because I am not using graphql subscriptions so there has to be a refresh of a kind.

What is a good solution so that while the user is using the site localstorage is used to track the counter, but when they return or refresh the page (not a component reload) I can update localstorage with the graphql query.

Here is my code thus far, thanks ahead of time.

0 投票
1 回答
154 浏览

faunadb - Fauna DB 在 Web 上显示来自 shell 的数据,但在终端 shell 中不起作用?

我正在学习动物数据库,但不能从终端外壳工作。

它在 webshel​​l 上显示数据。

但不会在终端外壳上显示数据。

0 投票
4 回答
2193 浏览

faunadb - 如何从动物群中的 Ref 获取 ID?

我正在从区区数据库中获取文档,并且我希望他们的 ID 出现在我发送给客户端的有效负载中。

这就是我获取文档并将其数据作为集合返回的方式

现在_id是参考。当我将它记录到控制台时看起来像这样:

当 JSON Stringifying 它时就像这样:

我基本上需要266565241615155713从那个 Ref 中获取 ID。我怎样才能做到这一点?我试过x.ref['@ref'].id@ref未定义。 文档在这里没有帮助我

提前感谢您的任何提示。

0 投票
1 回答
1721 浏览

go - 如何在 FaunaDB 中获取包含子字符串的文档

我正在尝试检索first名称中包含字符串的所有任务文档。

我目前有以下代码,但它只有在我传递确切名称时才有效:

我想我可以在ContainsStr()某处使用,但我不知道如何在我的查询中使用它。

另外,有没有办法在不使用的情况下做到这一点Filter()?我问是因为它似乎在分页后过滤,并且与页面混淆

0 投票
1 回答
53 浏览

faunadb - 如何使用您的登录密钥在动物数据库中获取客户字段数据?

在动物区系登录后,我需要进行查询以在动物区系中获取您自己的数据。我试过这个:

在此功能中,我只有客户端密钥,但没有您的参考。也许我需要进行查询以获取您的 id 并加入查询以获取您的数据...

0 投票
1 回答
122 浏览

node.js - FaunaDB 中的“由于检测到并发修改而中止事务”

我有一个可以从许多不同的并发请求写入的文档。文档的同一部分没有更改,但它可以看到并发写入(来自 nodejs 应用程序)。
例子:

我可以用“c”等更新文档。

如果我不异步等待事务(例如在测试中),我将收到部分写入和错误“由于检测到并发修改,事务被中止”.. 最好的方法是什么?我觉得 Fauna 的主要卖点是处理此类问题,但我没有足够的知识来理解我的解决方法。

有人有任何队列策略/想法/建议吗?

指数:

JS AWS Lambda 函数是在写什么..

0 投票
2 回答
267 浏览

faunadb - 如何选择一个项目并在动物区数据库中获取它的关系?

我有两个集合,其中包含以下格式的数据

我希望能够查询Leads集合并能够Sources在单个查询中检索相应的文档

我想出了以下查询来尝试使用索引,但我无法让它运行

有没有一种简单的方法来检索 Sources 文档?

0 投票
3 回答
1677 浏览

javascript - 在 FaunaDB 中更新记录时,如何在不传入每个字段和子对象的情况下更新一个字段?

也许我还没有掌握 GraphQL,但我想更新数据库中的复杂记录。我很难找到解释这一点的文档,它没有使用一个简单的例子。我正在使用 FaunaDB 并尝试在 GraphQL 操场上进行测试,然后再在 JS 中实现它。

这是我的架构的一个示例:

我想更新事件的一个字段:sentConfirmation,就是这样。

我知道事件 ID 以及我想将布尔值更新为什么。

有没有办法编写一个突变来只传递一个 ID 和更新的布尔值并更改该单个值,或者我是否需要逐字传递整个对象及其所有子对象,只更新一个顶级字段?

0 投票
1 回答
686 浏览

faunadb - 如何在 Fauna DB 中创建以键值对形式返回排序数据的索引

我正在尝试创建一个索引,该索引返回带有键的对象中的排序数据。我的集合的默认索引返回如下内容:

我使用以下代码在 shell 中创建了一个索引:

当我查看这个新索引时,排序是正确的,但它看起来像一个没有键的数组,如下所示:

有没有办法创建一个排序索引,只包含我需要的键值对数据?我浏览了文档,但无法弄清楚。谢谢。