CouchDB: Accessing Nested Structures in Map Functions

I have a document based on an xml structure that I have saved in a CouchDB database.

Some of the keys contain namespaces and are in the form "namespace: key":

{"mykey": {"nested:key": "nested value"}}

      

In the map function, I want to highlight the nested value as a key, but the colon inside the name makes it difficult ...

emit(doc.mykey.nested:key, doc)   <-- will not work. 

      

Does anyone know how this can be solved?

+2


a source to share


2 answers


Hint: All of its JSON and JavaScript gave me some new ideas to search for.

It is possible that the colon in json keys is not valid, but I found a way. Looking at the doc object as a hash, I can access its value like this:



Doc.mykey['nested:key']

      

It works - for now ...

+4


a source


This is because Couch is a JSON based document DB and doc.mykey.nested: key is not a valid JSON identifier. JSON IDs must match JavaScripts IDs and: is not a valid ID character.

So the simple answer is "No, it won't and can't work." You need to change your IDs.



Actually, I must qualify this.

The couch can use almost EVERYTHING for it by views et al, and theoretically works with any payload. But out of the box, it's just JavaScript and JSON.

0


a source







All Articles