Hi Couchbase community
I have a JSON document like this
“name1”: “some value”
I want to emit name1 ~ name3 for my view but Im not sure what is the right syntax to put in my document.get() method. I have tried doing
document.get(“name.name1”) and document.get(“name”.“name1”) but im not getting anything. has anyone dealt with this before?
Thanks in advance
Is this Java? You’d do
document.get("name"), cast the result to a Map, and then get
name1 from that.
Hi Jens, thank you for the suggestion, Yes it is Java
I tried doing it like this
emitter.emit( ( (Map) document.get(“name”) ).get(“name1”), null);
but I seem to be getting weird errors
It seems the return value type of
String. Please check how you stored the document.
It’s not a weird error, it’s just telling you that [in at least one document] the value of the
name property is a String, not a JSON object.
Remember that the map function gets called on every document in the database. If the documents don’t all have the same structure, you have to be careful in your map function.
I see, I understand, I am in the process of testing out some stuff. I have some documents that have
“name” : “some value”
and some the same as the example I have given above.
If I try to remove the documents where “name” contains string value this should now work, shouldn’t it?
Edit: Yes it did work Thanks Jens and hideki