我在视图中有一个非常简单的发出语句。
emit([doc.salesDate, doc.companyId], doc.grossSales);
有什么办法可以让它返回的 JSON 对象像这样显示
{
"grossSales" : "100"
}
代替
{
0: "100"
}
编辑:如果它有所作为,我正在使用其余的 API
我在视图中有一个非常简单的发出语句。
emit([doc.salesDate, doc.companyId], doc.grossSales);
有什么办法可以让它返回的 JSON 对象像这样显示
{
"grossSales" : "100"
}
代替
{
0: "100"
}
编辑:如果它有所作为,我正在使用其余的 API
Ideally you want the view to be as lightweight as possible but you can do this by simply emitting a JSON object
emit([doc.salesDate, doc.companyId], {"grossSales": doc.grossSales});
This assumes the document looks like this:
{
"salesDate": "2015-06-13T00:27:55.511Z",
"companyId": "Couchbase",
"grossSales": 100
}
The output from the REST API:
{"total_rows":1,"rows":[
{"id":"test","key":["2015-06-13T00:27:55.511Z","Couchbase"],"value":{"grossSales":100}}
]
}
Please note that the REST API for views should only be used for testing and debug. In a production environment a SDK should be used.