本文介绍了Cloudant支持将功能重写吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Cloudant数据库,我想为包含斜杠的文档提供漂亮的URL。所以我定义了这样的重写函数:

I have a Cloudant database, and I want to make pretty URLs for my slash-containing documents. So I define a rewrite function like so:

{
  "_id": "_design/myRewrites",
  "rewrites": "function (req2) {\n    return {path: \"../../../\" + req2.path.slice(4).join(\"%2F\")};\n}"
}

重写函数的格式很好:

function (req2) {
  return {path: "../../../" + req2.path.slice(4).join("%2F")};
}

,自CouchDB 1.7起,CouchDB就支持这种重写(作为字符串化函数),但是并未提及此特定功能(仅从数组进行重写)。

According to the CouchDB docs, CouchDB has supported this kind of rewriting (as stringified functions) since CouchDB 1.7, but Cloudant's documentation doesn't speak about this particular functionality (only rewrites from arrays).

当我尝试,我得到以下响应:

This is reflected in my experience when I try it out https://myAccount.cloudant.com/myDb/_design/myRewrites/_rewrite/hello/world/, I get the following response:

{"error":"unknown_command","reason":"unknown ddoc command 'rewrites'"}

但是我读到某个地方Cloudant和CouchDB从2.0开始就匹配了它们的源代码,因此我希望Cloudant支持所有CouchDB功能。这是怎么回事?

However I read somewhere that Cloudant and CouchDB match their source code since 2.0, so I would expect Cloudant to support all CouchDB features. What's the deal?

另请参阅以下有关此推文的内容,其中IBM要求我对StackOverflow提出问题,并建议我可能位于过时的集群中:

Also see following tweet about this, in which IBM asks me to make a question on StackOverflow and suggests I might be on an outdated cluster: https://twitter.com/digitalheir/status/845910843934085120

我的数据位置显示为 Porter,London。

My data location says "Porter, London". Could it help if I changed this?

推荐答案

tl; dr:,对不起,但没有。 Cloudant不支持函数重写:(

tl;dr: Sorry, but no. Cloudant doesn't support rewrites as functions :(

我们尝试了您的示例并获得了相同的结果。更深入地研究,我现在可以确定Cloudant不支持通过

We tried your example and got the same results. Digging deeper, I can now confirm that Cloudant does not support URL rewrites via stringified functions. The service only supports rewrites using the array approach.

我不能肯定地说,但我怀疑团队忽略了此功能。 Cloudant不太可能在短期内支持JS功能的重写,因为当前方法无法很好地扩展,因为如果频繁更新视图,它可能会使数据库陷入困境。这类似于Cloudant建议人们使用内置的reduce函数的原因(

I can't say for sure, but I suspect that the team overlooked this feature. That said, it's unlikely that Cloudant will support rewrites as JS functions anytime soon because the current approach does not scale well, as it can bog down the database if views are frequently updated. It's similar to the reason that Cloudant recommends people use the built-in reduce functions (which are implemented in Erlang), rather than writing their own custom JavaScript reduces.

但是重写为数组确实可以扩展,但是这种方法显然行不通。正在动态生成URL。在这种情况下,我们建议将URL重写功能移至应用服务器。不幸的是,如果您要构建CouchApp,那么所有这些都可能是有争议的:/

Rewrites as arrays, however, does scale. But this approach obviously won't work if you're dynamically generating URLs. In this case, we suggest moving the URL rewrite functionality to an app server. Unfortunately, this all might be a moot point if you're building a CouchApp :/

这令人困惑,因此感谢您指出这一点。我要请Cloudant团队在文档中记录这种差异。希望这至少有助于提供一些封闭。您没错,期望它能正常工作。

This was confusing, so thank you for pointing it out. I'm going to ask the Cloudant team to note this difference in the documentation. Hope this at least helps provide some closure. You weren't wrong for expecting it to work.

这篇关于Cloudant支持将功能重写吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-14 23:26