I am trying to query the following data:
(obtained from: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
}
]
},
..........
My question:
- How to include, say, firstly, the place_name, in the query.
The following javascript does not give a result:
{
"selector": {
"post_code": {"$eq": 35801}
},
"fields":["places.placename"]
}
correct index on post_code:
{
"index": {
"fields": [
"post_code"
]
},
"type": "json",
"name": "post-code-index"
}
I did set up an additional index as follows:
{
"index": {
"fields": [
"places.placename"
]
},
"type": "json"
}
What if the data had the following field:
"old_post_code_numbers": [12345, 67890, ......]
or:
What if the data had the following fields:
"places": { "place_name": "Huntsville", "longitude": -86.5673, "state": "Alabama", "state_abbreviation": "AL", "latitude": 34.7269 }
JSON has so many forms and I struggle to get a handle on the principles behind the javascript required for these kind of queries. I know it is simple. It must be simple.
Many thanks for any guidance or websites I should/could visit.
Edit:
I managed to get the following to work on an online javascript testing site, but I still could not get this to work in CouchDB Mango. Surely this is possible in 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);
places[0].place_name
. Thanks.