Hello,
I am building a view to return some attribute values of a JSON document separated by comma “,”;
For example I have the following JSON:
{
“type”: “product”,
“dateTime”: “2015-07-20”,
“Category”: “test”,
“productID”: “8”,
“productName”: “p1”,
“valID”: “p1-1”,
“valValue”: “8”,
“userName”: “user5204”,
“userID”: “5204”,
“city”: “dublin”
}
I have created the following Map function ; (reduce function I leave it empty)
function (doc, meta) {
var date = new Date();
date.setDate(date.getDate() - 8); //// should be equal to 2015-07-20
MyDateString = date.getFullYear() + ‘-’ + (‘0’ + (date.getMonth()+1)).slice(-2) + ‘-’
+ (‘0’ + date.getDate()).slice(-2)
;
if(meta.type==“json” && doc.type==“product” && MyDateString == doc.dateTime) {
emit([doc.Category + doc.productID, doc.productName, doc.valID,doc.valValue
,doc.userName,doc.userID,doc.city] );
}
}
But the result I have is not the expected;
I am getting the following result;
p1-1,[“test”,“8”,“p1”,“p1-1”,“8”,“user5204”,“5204”,“dublin”],{
“type”: “product”,
“dateTime”: “2015-07-20”,
“Category”: “test”,
“productID”: “8”,
“productName”: “p1”,
“valID”: “p1-1”,
“valValue”: “8”,
“userName”: “user5204”,
“userID”: “5204”,
“city”: “dublin”
}
what I want to have is just the following;
“test”,“8”,“p1”,“p1-1”,“8”,“user5204”,“5204”,“dublin”
can someone help me ?
thanks
W