如何查找重复文件? [英] How to find duplicates documents?

查看:25
本文介绍了如何查找重复文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

很奇怪我没有在文档和这里找到一个非常简单的问题的答案.如何在集合中查找重复记录.例如,我需要为下一个文档找到 id 的重复项:

{id": 1, name: Mike"},{id":2,名称:Jow"},{id":3,名称:Piter"},{id":1,姓名:罗伯特"}

我需要查询将返回两个具有相同 ID 的文档(在我的例子中为 id: 1).

解决方案

看看 COLLECT AQL 命令,它可以返回包含重复值的文档计数,例如您的 id 键.

ArangoDB AQL - 收集

您可以在 AQL 中大量使用 LET 来帮助将查询分解为更小的步骤,并在以后的查询中处理输出.

也可以将其全部折叠为一个查询,但这种技术有助于将其分解.

LET 重复 = (FOR d 在我的收藏中COLLECT id = d.id WITH COUNT INTO count过滤器计数>1返回 {身份证:身份证,计数:计数})FOR d IN 重复FOR m 在我的收藏中过滤器 d.id == m.id返回米

这将返回:

<预><代码>[{_key":416140",_id":myCollection/416140",_rev":_au4sAfS--_",id":1,姓名":迈克"},{_key":416176",_id":myCollection/416176",_rev":_au4sici--_",id":1,姓名":罗伯特"}]

It's very strange that I did not find answer in documentation and here for a very simple question. How to find duplicated records in collections. For example I need to find duplicated by id for next documents:

{"id": 1, name: "Mike"},
{"id": 2, name: "Jow"},
{"id": 3, name: "Piter"},
{"id": 1, name: "Robert"}

I need to query that will return two documents with same id (id: 1 in my case).

解决方案

Have a look at the COLLECT AQL command, it can return the count of documents that contain duplicate values, such as your id key.

ArangoDB AQL - COLLECT

You can use LET a lot in AQL to help break down a query into smaller steps, and work with the output in future queries.

It may be possible to also collapse it all into one query, but this technique helps break it down.

LET duplicates = (
    FOR d IN myCollection
    COLLECT id = d.id WITH COUNT INTO count
    FILTER count > 1
    RETURN {
        id: id,
        count: count
    }
)

FOR d IN duplicates
FOR m IN myCollection
FILTER d.id == m.id
RETURN m

This will return:

[
  {
    "_key": "416140",
    "_id": "myCollection/416140",
    "_rev": "_au4sAfS--_",
    "id": 1,
    "name": "Mike"
  },
  {
    "_key": "416176",
    "_id": "myCollection/416176",
    "_rev": "_au4sici--_",
    "id": 1,
    "name": "Robert"
  }
]

这篇关于如何查找重复文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆