there is something I wonder: In my map reduce function, can I take "parent" property as a variable ? Like that :
function (doc, meta) {
var key,value;
if(doc.type == "mainForums" && doc.parent == **VAR**){
key = [doc.type,doc.id]
value = {Id : doc.id, Title : doc.title, Description : doc.description, Parent: doc.parent, HasChild : doc.hasChild, Level : doc.level, ImageUrl : "http://icon.donanimhaber.com/mobile-forum-icons/" + doc.iconPath, AvarageColor: doc.avarageColor, RepMode : doc.repMode, iconPath : doc.iconPath, MessageCountThisWeek : doc.messageCountThisWeek, TopicCountThisWeek : doc.topicCountThisWeek}
emit(key, value);
}
}
Since I'm creating map reduce function on the couchbase console, I don't get how can I add a variable to this function. I'm doing the mapping part on MVC, as below:
var tempForum = new Forum
{
Id = item.Id,
Title = item.Title,
Description = item.Description,
HasChild = item.HasChild,
Level = item.Level,
iconPath = item.iconPath,
Parent = item.Parent,
IsFavorite = item.IsFavorite,
TopicCountThisWeek = item.TopicCountThisWeek,
MessageCountThisWeek = item.MessageCountThisWeek,
RepMode = item.RepMode,
ForumExtra = item.ForumExtra
}
to print the json on the screen properly. I should take what mobile(android) programmer gives me as a variable, lets say 4, and bring him parent=4 docs from the sync_gateway. Or should android programmer do that map reduce thing?
Maybe I should forget about views and use only N1QL on a situation like that? Because I'm able to do it with N1QL but i want to do it with views too, because I may need views later. I'm not really sure what is the best and I'm really confused.
Thanks a lot.
I don't think this is a good use case for views, which can't be parameterized and are not really build to return a full hierarchy of documents.
The value
you emit
is what gets stored in the index (and passed to the reduce
function), so it's really redundant to store full contents, generally not a good idea.
The configurable number of parents bit is even further from what views can support AFAIK.
So I'd advise to stick with N1QL, or maybe find a way to do that half on the server (N1QL), half on the client?