如何为以下情况设计 couchdb 视图?
我正在将应用程序从 mySQL 迁移到 couchDB。 (好吧,请不要对此做出判断)。
有一个带有签名的函数
getUserBy($column, $value)
现在您可以看到,对于 SQL,构建查询并触发它是一项微不足道的工作。
然而,就 couchDB 而言,我应该使用地图函数编写视图,
目前我有很多视图,例如
get_user_by_name
get_user_by_email
等等。谁能建议一种更好且可扩展的方法来做到这一点?
I am migrating an application from mySQL to couchDB. (Okay, Please dont pass judgements on this).
There is a function with signature
getUserBy($column, $value)
Now you can see that in case of SQL it is a trivial job to construct a query and fire it.
However as far as couchDB is concerned I am supposed to write views with map functions
Currently I have many views such as
get_user_by_name
get_user_by_email
and so on. Can anyone suggest a better and yet scalable way of doing this ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当然!由于其强大功能,我最喜欢的视图之一是
by_field
。这是一个非常简单的地图功能。假设您的文档有一个
.name
字段作为其姓名,并使用.email
字段作为其电子邮件地址。按姓名获取用户(例如“Alice”和“Bob”):
通过电子邮件获取用户,从同一视图:
我喜欢发出
1
的原因是这样您可以稍后编写reduce 函数使用sum()
轻松添加与您的查询匹配的文档。Sure! One of my favorite views, for its power, is
by_field
. It's a pretty simple map function.Suppose your documents have a
.name
field for their name, and.email
for their email address.To get users by name (ex. "Alice" and "Bob"):
To get users by email, from the same view:
The reason I like to emit
1
is so you can write reduce functions later to usesum()
to easily add up the documents that match your query.