Documentdb存储的proc跨分区查询

编程入门 行业动态 更新时间:2024-10-27 02:29:03
本文介绍了Documentdb存储的proc跨分区查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个存储过程,可以给我一个文档计数( count.js on github ).我已经对收藏进行了分区.因此,我现在必须传递分区键作为运行存储过程的选项.

I have a stored procedure which gives me a document count (count.js on github). I have partitioned my collection. Due to this, I now have to pass the partition key in as an option to run the stored procedure.

可以并且应该如何在存储过程(即collection(EnableCrossPartitionQuery = true))中启用跨分区查询,以便不必指定分区键?

Can and how should I enable crosspartition queries in the stored procedure (ie, collection(EnableCrossPartitionQuery = true)) so that I don't have to specify the partition key?

推荐答案

无法在DocumentDB中执行扇出存储过程的执行.针对单个分区运行.当尝试切换到分区集合时,我遇到了这个难题,必须进行一些调整.以下是一些选项:

There is no way to do fan-out stored procedure execution in DocumentDB. The run against a single partition. I ran into this dilemma when trying to switch to partitioned collections and had to make some adjustments. Here are some options:

  • 为每条记录下载1,并在客户端对它们进行总计/计数

  • Download a 1 for every record and sum/count them client-side

    为每个唯一分区键重新运行存储过程.就我而言,这并不像听起来那样糟糕,因为分区键是一个tenantID,而我只有十几个,并且最多只能看到几百个.

    Rerun the stored procedure for each unique partition key. In my case, this was not as bad as it sounds since the partition key is a tenantID and I only have a dozen of those and only expect a few hundred max.

    我不确定这一点,因为我还没有对分区集合进行尝试,但是现在每个查询都在x-ms-resource-usage标头中返回集合的资源使用情况.该标头具有documentsSize子标头.您可以将其除以文档的平均大小,以获得一个近似的计数.到目前为止,该标头信息中甚至还可能有一个计数记录.

    I'm not sure about this one since I haven't tried it with partitioned collections, but each query now returns the resource usage of the collection in the x-ms-resource-usage header. That header has a documentsSize sub-header. You could use that divided by the average size of your documents to get an approximate count. There may even be a count record in that header information by now.

    此外,还有一个x-ms-item-count标头,但我不确定它的行为.如果您对整个分区集合中的所有记录发送查询,并将max-item-count设置为1,则只会返回一条记录,因此您不会在RU上花费很多,但我不会知道标题的行为.在这种情况下,它是否返回1?还是返回所有查询页面最终将返回的文档总数,如果您不愿意请求每一页.快速实验应该可以证实这一点.

    Also, there is an x-ms-item-count header but I'm not sure how that behaves. If you send a query for all the records in the entire partitioned collection and set the max-item-count to 1, you'll only get back one record and it shouldn't cost you a lot in RUs, but I don't know how that header behaves. Does it return a 1 in that case? Or does it return the total number of documents all the pages of the query would eventually return if you bothered to request every page. A quick experiment should confirm this.

  • 更多推荐

    Documentdb存储的proc跨分区查询

    本文发布于:2023-10-20 03:40:08,感谢您对本站的认可!
    本文链接:https://www.elefans.com/category/jswz/34/1509732.html
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:分区   Documentdb   proc

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!