将值传递给地图函数-CouchDB [英] Passing values to a map function - CouchDB
问题描述
我想知道是否有可能将值传递给bedDB设计文档中的map函数.
I was wondering whether its possible to pass values to a map function in couchDB design document.
例如:
在下面的代码中,可以传递用户输入的值,然后使用该值来运行map函数.也许我可以在用户登录时传递 UserName 用户,然后基于地图功能显示视图.
In the code below is it possible to pass a value that has been entered by the user and use that value to run the map function. Maybe I can pass users UserName when they login and then display the view based on the map function.
function(doc) {
if(doc.name == data-Entered-By-User) {
emit(doc.type, doc);
}
}
先谢谢您. 问候
推荐答案
在使用视图时,这是CouchDB中的常见错误.有点令人困惑,但要代替它:
This is a common mistake in CouchDB when using views. It's kinda confusing, but instead of this:
function (doc) {
if (doc.value === 'thing I am looking for') {
emit(doc.value);
}
}
您想要的是什么
function (doc) {
emit(doc.value);
}
然后,当您查询时,您将执行以下操作:
And then when you query, you do:
/mydb/_design/myddoc/_view/myview?key="thing I am looking for"
You might want to read my 12 pro tips for better code with PouchDB, especially tip #9. The tips apply equally well to CouchDB. :)
这篇关于将值传递给地图函数-CouchDB的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!