Reputation: 545
I'm working with cloudantDB as DB for my spring application.
The thing that I'm trying to do is:
check if there is a timeslot and topic in the document
if there is a topic filled in:
check the userId who has submitted that topic and return all of the items for that user.
{
"_id": "393c7748cf487f7c5223839dfdf5adf9",
"_rev": "2-889c6d9d14fcc3c90a00e91aca5f2f4c",
"name": "conference 1",
"type": "conference",
"location": "conf loc",
"tag": "confTag",
"startDate": "2015-05-04T22:00:00.000+0000",
"endDate": "2015-05-08T22:00:00.000+0000",
"timeslots": {
"8a03b160-48e3-4f99-be38-2a2da34e5890": {
"id": "8a03b160-48e3-4f99-be38-2a2da34e5890",
"startDate": "2015-04-07T10:45:00.000+0000",
"endDate": "2015-05-07T12:45:00.000+0000",
"location": "Location",
"topic": {
"id": "4ad235ef-5938-4461-8a2e-346bf105c5b6",
"title": "wa nen coole title",
"description": "dees is een goei omschrijving",
"tags": "cloud, tag",
"attachment": "file.exe",
"speakerId": null
}
},
"a59b1dfd-d1c5-491f-bc02-807e38595ba4": {
"id": "a59b1dfd-d1c5-491f-bc02-807e38595ba4",
"startDate": "2015-05-05T10:00:00.000+0000",
"endDate": "2015-05-05T11:15:00.000+0000",
"location": "mlkjs",
"topic": {
"id": "8b753adb-9a15-486f-9209-b9cc5ef134a1",
"title": "test132",
"description": "met speakerId",
"tags": "sldkjf",
"attachment": "kklsjdf",
"speakerId": "speaker"
}
},
"080153e7-f8bc-453e-b49a-a1df4679ceef": {
"id": "080153e7-f8bc-453e-b49a-a1df4679ceef",
"startDate": "2015-05-09T11:30:00.000+0000",
"endDate": "2015-05-09T13:30:00.000+0000",
"location": "file upload",
"topic": {
"id": "e3533a60-a0ba-4439-a9e9-b29e69be47db",
"title": "fdgdfg",
"description": "fdsgdsggdfgdfg",
"tags": "dfgsdg",
"attachment": null,
"speakerId": null
}
}
},
"defaultTwitterText": "Hallo",
"twitterUrl": "https://twitter.com/intent/tweet?button_hashtag=confTag&text=Hallo"
}
So far I have this:
function(doc) {
{ if (doc.type === 'conference') {
if(doc.timeslots.size !==0 ){
emit( null, doc);
}
}
}
}
Thanks!
Upvotes: 0
Views: 42
Reputation: 116
I think you might want something like:
function (doc) {
if (doc.type == 'conference'){
if (doc.timeslots){
for (var i in doc.timeslots) {
if(doc.timeslots[i].topic){
emit(doc.timeslots[i].topic.speakerId, doc.timeslots[i])
}
};
}
}
}
that'll make a view of key:speaker, value: topic object
, which you can then query with ?key=speaker
to see the list of all the topic objects for the speaker.
Upvotes: 2