- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
所以对于这个Person
,Company
示例:
type Person {
name: string
work_for: [Company]
}
type Company {
name: string
work_for: [Person]
}
work_for: [uid] @reverse @count .
name: string @index(fulltext, term) @count .
查询要查找什么:所有拥有“John James Sam”的公司以及每个公司的这些名称的总数
?我试过:
q(func: anyofterms(hashed, "Jame John Sam")){
uid
@groupby work_for{
name
count(uid)
}
}
}```
but that gives the person and the companies they worked for plus the count which is not the company and the number of people with those names that worked for it. Thanks in advance
最佳答案
检查这是否适合您。 (让我们用我的示例来弄清楚这个问题)
{
var(func: anyofterms(name, "Alexei Jack Jose Zoe Ivy")) @groupby(works_for) {
a as count(uid)
}
q(func: uid(a), orderdesc: val(a)) {
name
total_workers : val(a)
workHere: ~works_for @groupby(name){
count(uid)
}
}
}
此查询并不完美,因为它利用了 GroupBy 中未实现的功能。但是,您可以使用它或期望 GroupBy 函数得到改进。
{
"data": {
"q": [
{
"name": "CompanyABC",
"total_workers": 6,
"workHere": [
{
"@groupby": [
{
"name": "Ivy",
"count": 2
},
{
"name": "Jack",
"count": 2
},
{
"name": "Zoe",
"count": 2
}
]
}
]
},
{
"name": "The other company",
"total_workers": 4,
"workHere": [
{
"@groupby": [
{
"name": "Alexei",
"count": 2
},
{
"name": "Jose",
"count": 2
}
]
}
]
}
]
}
}
使用此数据集作为引用:https://tour.dgraph.io/master/schema/2/
我已经对其进行了编辑,它看起来像这样:
{
set {
_:company1 <name> "CompanyABC" .
_:company1 <dgraph.type> "Company" .
_:company2 <name> "The other company" .
_:company2 <dgraph.type> "Company" .
_:company1 <industry> "Machinery" .
_:company2 <industry> "High Tech" .
_:jack <works_for> _:company1 .
_:jack <dgraph.type> "Person" .
_:ivy <works_for> _:company1 .
_:ivy <dgraph.type> "Person" .
_:zoe <works_for> _:company1 .
_:zoe <dgraph.type> "Person" .
_:jack <name> "Jack" .
_:ivy <name> "Ivy" .
_:zoe <name> "Zoe" .
_:jose <name> "Jose" .
_:alexei <name> "Alexei" .
#duplicated
_:jack2 <name> "Jack" .
_:jack2 <works_for> _:company1 .
_:jack2 <dgraph.type> "Person" .
_:ivy2 <name> "Ivy" .
_:ivy2 <works_for> _:company1 .
_:ivy2 <dgraph.type> "Person" .
_:zoe2 <name> "Zoe" .
_:zoe2 <works_for> _:company1 .
_:zoe2 <dgraph.type> "Person" .
_:jose2 <name> "Jose" .
_:jose2 <works_for> _:company2 .
_:jose2 <dgraph.type> "Person" .
_:alexei2 <name> "Alexei" .
_:alexei2 <works_for> _:company2 .
_:alexei2 <dgraph.type> "Person" .
#duplicated end
_:jose <works_for> _:company2 .
_:jose <dgraph.type> "Person" .
_:alexei <works_for> _:company2 .
_:alexei <dgraph.type> "Person" .
_:ivy <boss_of> _:jack .
_:alexei <boss_of> _:jose .
}
}
关于graphql - 如何分组和计算dgraph,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58311554/
我正在使用 Dgraph 编写一个 Golang 应用程序来持久化对象。从文档中,我可以推断出一个新的 UID,因此每次我改变一个对象/运行代码时都会创建一个新节点。 有没有办法更新相同的节点数据而不
在使用 Dgraph go 客户端时是否可以使用带有正则表达式搜索的变量? 我们可以使用 SprintF 构建查询,但那样是不安全的。 q :=query Search($searchterm: st
我按照 here 上的文档使用 --reduce_shards=2 从 bulkloader 生成数据 这会生成 2 个 p 目录,我在这些目录上运行 alphas 之后 link 我使用的命令dgr
关于 Dgraph 在图遍历方面的功能,我有几个问题。 假设我们有一个由 post 类型的节点组成的数据集。每个帖子可以有 n 个帖子,这些帖子是对该帖子的回复。这棵树的深度没有限制。 Dgraph是
我是 dgraph 的初学者,正在从 neo4j 转向 dgraph。我正在编写架构,其中有不同的社交媒体平台详细信息。 考虑到 facebook,该模式将包含个人资料、组、页面的基本详细信息以及 f
我正在通过建议的 docker 图像运行 Dgraph 数据库和界面。是否可以运行从数据库中删除所有数据并保留架构的命令?或者至少同时删除数据和模式?还是我只需要删除 docker 镜像并重建它们?
我安装了 dgraph gru 用于面试 go get github.com/dgraph-io/gru cd $GOPATH/src/github.com/dgraph-io/gru git che
我需要能够在不使用 newBuilder() 的情况下运行原始字符串突变查询: Gson gson = new Gson(); String json = gson.toJson(newEmploye
我是DGraph的新手。因此,我正在尝试 dgraph4j 示例并对其进行了一些修改。 在示例中,我尝试查询以下数据: { "all":[ { "name":"Al
我正在寻找一个低延迟图形数据库,它允许进行深度查询,同时实时更新。是否可以通过Flink进程实时更新Dgraph?我想验证一个想法如下: 读取 Kafka 中的流传递给 Flink 以创建数据表/图形
我是 lagom 和 dgraph 的新手。我陷入了如何将 lagom 的读取端处理器与 Dgraph 结合使用的困境。只是为了给您一个想法,以下是使用 Cassandra 和 lagom 的代码。
我是 Swift 新手,但对 PHP 来说并不陌生,但我无法找到有关如何连接到位于 AWS 上的远程 Dgraph 数据库的任何说明。任何有关如何从该类型的数据库获取数据的教程的指示将不胜感激。 我尝
我正在使用dgraph-orm 来获取嵌套关系值,但它适用于单级别,但不适用于多级别。我正在获取页面详细信息,但无法获取页面的头像。 这是我的片段: let posts = await PagePos
我希望我的标题简洁但足够具体: 我想做的 导出/备份整个 DGraph 数据库。 最佳答案 执行docker exec -it curl localhost:8080/admin/export 确定
早期版本的dgraph-orm默认提供查询日志记录,但在最新更新后它已被关闭。那么有什么办法可以开启日志记录呢?我需要调试并查明所触发的查询是否正确。 这是我尝试过的: dgraph.conn
是否可以使用 api.NQuad 从给定节点中删除与谓词匹配的所有边?来自 github.com/dgraph-io/dgo/protos/api ? 我正在努力实现相当于 delete {0x123
我是一名优秀的程序员,十分优秀!