无法将“key”查询字符串参数获取到 select 特定行
Cannot get `key` query string parameter to select a specific row
我一直在用头撞墙。查询文档时无法将 key
查询字符串参数获取到 select 特定行。这是一个 运行 针对新数据库的脚本,显示我可以查询所有文档,但不能 select 仅通过其键:
#!/usr/bin/env bash -ex
# Create a database.
curl -X PUT http://localhost:5984/names
# Add a few documents.
curl -X POST -H 'Content-Type: application/json' -d '{"name":"joe"}' http://localhost:5984/names
curl -X POST -H "Content-Type: application/json" -d '{"name":"frank"}' http://localhost:5984/names
# Add a view function.
curl \
-X PUT \
-H 'Content-Type: application/json' \
-d '{ "views": { "by_name": { "map": "function (doc) { if (doc.name) { emit(doc.name, doc.name.toUpperCase()) } }" } } }' \
http://localhost:5984/names/_design/docs
# Querying all the documents works.
curl -X GET http://localhost:5984/names/_design/docs/_view/by_name
# Selecting one of those documents by key does not work.
curl -X GET http://localhost:5984/names/_design/docs/_view/by_name?key=frank
据我所知,我正在按照 CouchDB 文档 "Find One" 部分第一段中的示例进行操作。
您的密钥应该是 JSON 编码的,因此请改用 key="frank"
。 (就像在示例中一样)
我一直在用头撞墙。查询文档时无法将 key
查询字符串参数获取到 select 特定行。这是一个 运行 针对新数据库的脚本,显示我可以查询所有文档,但不能 select 仅通过其键:
#!/usr/bin/env bash -ex
# Create a database.
curl -X PUT http://localhost:5984/names
# Add a few documents.
curl -X POST -H 'Content-Type: application/json' -d '{"name":"joe"}' http://localhost:5984/names
curl -X POST -H "Content-Type: application/json" -d '{"name":"frank"}' http://localhost:5984/names
# Add a view function.
curl \
-X PUT \
-H 'Content-Type: application/json' \
-d '{ "views": { "by_name": { "map": "function (doc) { if (doc.name) { emit(doc.name, doc.name.toUpperCase()) } }" } } }' \
http://localhost:5984/names/_design/docs
# Querying all the documents works.
curl -X GET http://localhost:5984/names/_design/docs/_view/by_name
# Selecting one of those documents by key does not work.
curl -X GET http://localhost:5984/names/_design/docs/_view/by_name?key=frank
据我所知,我正在按照 CouchDB 文档 "Find One" 部分第一段中的示例进行操作。
您的密钥应该是 JSON 编码的,因此请改用 key="frank"
。 (就像在示例中一样)