jcbanez
February 20, 2017, 4:42pm
1
Hi Couchbase community
I have a JSON document like this
{
“name”: {
“name1”: “some value”
“name2”:“some value”
“name3”:“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
jens
February 20, 2017, 5:43pm
2
Is this Java? You’d do document.get("name")
, cast the result to a Map, and then get name1
from that.
1 Like
jcbanez
February 20, 2017, 6:01pm
3
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
hideki
February 20, 2017, 6:22pm
4
@jcbanez ,
It seems the return value type of document.get("name")
is String
. Please check how you stored the document.
Thanks.
1 Like
jens
February 20, 2017, 6:23pm
5
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.
1 Like
jcbanez
February 20, 2017, 6:32pm
6
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.
“name” :
{
“name1”:“some value”,
“name2”:“some value”,
“name3”:“some value”
}
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