使用N1QL查询同步网关存储桶 [英] Query sync gateway buckets using N1QL

查看:54
本文介绍了使用N1QL查询同步网关存储桶的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否可以使用N1QL查询同步网关存储桶?它是否像普通的沙发式存储桶一样工作,还是由于同步网关添加了元数据,是否只能通过Rest API对其进行查询?

I wanted to know if it's possible to query the sync gateway buckets using N1QL? Does it behave as a normal couchbase bucket or because of the metadata that sync gateway adds, is it possible to query it only through Rest APIs?

当前,我有一个webhooks处理程序,该处理程序将驻留在同步网关存储桶下的文档的副本保留下来.我需要做一些凝集,将其推回给客户.因此,我可以直接通过n1ql在同步网关上进行所有这些繁重的工作,还是使用webhooks进行聚合,并简单地将更新后的文档推送到同步网关,这是正确的选择吗?

Currently I have a webhooks handler, which keeps a replica of the documents residing under sync gateway buckets. I need to do some aggrgations which need to be pushed back to clients. So, can I do all this heavy lifting directly trhough n1ql on sync gateway or using webhooks which does the aggregations and simply pushes the updated docs to sync gateway is the right option?

PS:webhooks + Rest APIS选项目前非常适合我.只是想了解这一跳是否必要?

PS: The webhooks+Rest APIS option works perfectly for me currently. Just wanted to understand if this hop is necessary or not?

推荐答案

是的,可以使用N1QL查询同步网关-您无法更改(更新/删除/插入),因为它会破坏修订的元数据.

Yes, it is possible to query the sync gateway using N1QL - you just can't change it (update/delete/insert), as it would break the revisions' metadata.

您需要忽略ID以 _sync:开头的文档以及每个文档的 _sync 属性(包含内部元数据).其余属性是您的常规文档.

You need to ignore the documents with IDs starting with _sync: and the _sync property of each document, which contains internal metadata. The remaining attributes are your usual document.

示例:

select db.* from db where meta().id not like '_sync:%'

结果:

[
  {
    "_sync": {
      "history": {
        "channels": [
          null,
          null
        ],
        "parents": [
          -1,
          0
        ],
        "revs": [
          "1-b7a15ec4afbb8c4d95e2e897d0ec0a2e",
          "2-919b17d3f418100df7298a12ef2a84bb"
        ]
      },
      "recent_sequences": [
        6,
        7
      ],
      "rev": "2-919b17d3f418100df7298a12ef2a84bb",
      "sequence": 7,
      "time_saved": "2016-05-04T18:54:26.952202911Z"
    },
    "name": "Document with two revisions"
  }
]

忽略 _sync 属性:

select name from db where meta().id not like '_sync:%'

结果:

[
  {
    "name": "Document with two revisions"
  }
]

在Couchbase 4.5(今天的测试版)中,我们可以使用 object_remove 函数-尽管我会避免使用它来支持以前更明确的语法.

In Couchbase 4.5 (BETA as of today) we can use the object_remove function - although I'd avoid it in favor of the previous more explicit syntax.

select object_remove(db, '_sync') from db where meta().id not like '_sync:%'

结果:

[
  {
    "$1": {
      "name": "Document with two revisions"
    }
  }
]

我不知道您当前的设置是什么,但是AFAIK,在使用REST API进行数据更改时,始终通过N1QL查询存储区是非常好的.

I don't know what's your setup currently, but AFAIK, it's perfectly fine to keep querying the bucket throught N1QL while using the REST API for the data changes.

这篇关于使用N1QL查询同步网关存储桶的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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