我正在尝试查询以下数据:
(来自:https ://dotnetcodr.com/2017/06/21/introduction-to-couchdb-with-net-part-17-starting-with-mango-queries/ )
{
"post_code": 35801,
"country": "United States",
"country_abbreviation": "US",
"places": [
{
"place_name": "Huntsville",
"longitude": -86.5673,
"state": "Alabama",
"state_abbreviation": "AL",
"latitude": 34.7269
}
]
},
..........
我的问题:
- 如何在查询中首先包含 place_name。
以下 javascript 没有给出结果:
{
"selector": {
"post_code": {"$eq": 35801}
},
"fields":["places.placename"]
}
post_code 上的正确索引:
{
"index": {
"fields": [
"post_code"
]
},
"type": "json",
"name": "post-code-index"
}
我确实设置了一个附加索引,如下所示:
{
"index": {
"fields": [
"places.placename"
]
},
"type": "json"
}
如果数据具有以下字段怎么办:
"old_post_code_numbers": [12345, 67890, ......]
或者:
如果数据具有以下字段怎么办:
"places": { "place_name": "Huntsville", "longitude": -86.5673, "state": "Alabama", "state_abbreviation": "AL", "latitude": 34.7269 }
JSON 有很多形式,我很难掌握这类查询所需的 javascript 背后的原理。我知道这很简单。一定很简单。
非常感谢我应该/可以访问的任何指导或网站。
编辑:
我设法让以下内容在在线 javascript 测试站点上工作,但我仍然无法在 CouchDB Mango 中工作。当然这在 CouchDB 中是可能的。???
var xxx=
{
"post_code": 82941,
"country": "United States",
"country_abbreviation": "US",
"places": [
{
"place_name": "Pinedale",
"longitude": -109.8561,
"state": "Wyoming",
"state_abbreviation": "WY",
"latitude": 42.8543
}]
}
console.log(xxx.places[0].place_name);