Search code examples
couchdbcloudant

Cloudant view still including unwanted id keys outside from the DOC


I can't get rid of unwanted data when using couchdb cloudant database .

I've done a couchdb view, an array of objects like this :

[
{},
{}
]

LOOK AT THE WELL DONE VIEW

Now, when querying couchdb, it is still sending bad formatted array of objects :

https://1c54473b-be6e-42d6-b914-d0ecae937981-bluemix.cloudant.com/footballers/_design/footballers/_view/football?include_docs=true

i only want this :

[
{mydoc1content},
{mydoc2content}
]

And it currenlty gives me this :

[
{id:1,value:1:key:1;doc:{mydoc1content}},
{id:2,value:2:key:2;doc:{mydoc2content}}
]

How to only get the docs ? not the unwanted id, key and docs values ? I think it is called 'metadata', how to get rid of theses unwanted metadata stuffs ? It blocks me from developping further.

Gives :

total_rows  16
offset  0
rows    
0   
id  "1"
key "1"
value   1
doc {…}
1   
id  "10"
key "10"
value   1
doc {…}
2   
id  "11"
key "11"
value   1
doc 
_id "11"
_rev    "1-b532f5d0dbc395875dc5fb04bce8fb58"
identifiant 11
prenom  "Ricardo"
nom "Izecson dos Santos Leite"
categorie   1
ville   "São Paulo"
age 34
date_embauche   "2017-06-26T22:00:00.000Z"
salaire 950
vitesse 85
agilite 70
deduction   54
photo   "kaka.jpg"
poste   "Milieu Offensif"
3   

This is badly formatted, i can't use it in my application . How could i get rid of id "1" key "1" value 1 and only get a simple array of objects ?


Solution

  • As I suggested on the Github repository of CouchDB, you should manipulate the data after querying it.

    For example, you could do the following:

    const getDocsFromViewResult = rawData => rawData.map(entry => entry.doc);
    
    const data = [{
      id: 1,
      key: 1,
      doc: {
        _id: '1234',
        name: 'johnny'
      }
    }];
    
    console.log(getDocsFromViewResult(data));