I've googled and tried the hell out of this, and it seems like it's just not possible. Maybe (hopefully) someone knows better :D
So I have a Cloudant database running on Bluemix, which I'm both very new to. Queries, indexes, views... struggling a bit here, but so far I can successfully retrieve documents – in my case filtered by timestamp
. Now I just want to make the output a bit handier.
In my database I have documents structured like so:
{
"_id": "0048160a463a73faaa6c90f5af027772",
"_rev": "1-ff6255309f1b873a4e482310843a8a15",
"timestamp": 1496275536932.6602,
"results": {
"lines": {
"S1": [
{
"needed_key": "foo",
"not_needed_key": 1
}
],
"S2": [
{
"needed_key": "bar",
"not_needed_key": 1
},
{
"needed_key": "foo_bar",
"not_needed_key": 1
}
],
...
}
},
"station": "5002270",
"another_not_needed_key": "something"
}
Shortened, my Cloudant selector looks somewhat like this:
{
"selector": {
"$and": [{
"timestamp": {
"$gte": from,
"$lt": to
},
"results.lines": {
"$ne": {}
}
]},
"fields": [
"_id",
"timestamp",
"station",
"results"
],
...
}
See how "another_not_needed_key"
is not in fields
, because, well, I don't need that info. Now I want to do the same thing for the unneeded fields within the objects of the lines
array.
I've read somewhere that, for arrays, something like
"results.lines.S1.[].needed_key"
as a selector
is possible, although I'm not even sure if I got any results testing this. Anyway:
Questions:
- Will/should the above work for
fields
, too? I.e. should it only output the"needed_key"
of any in the"S1"
array nested objects? Haven't had success with it yet. - Can I generalize the
"S1"
somehow? Like with the[]
for all objects of the array, I want to address all keys withinlines
. Because: Some may contain"S1"
as a key, others not. Overall, there are seven possible keys here, variably combined.
If anything is unclear, I'm happy to provide more info. Thanks in advance!