Monday 15 July 2013

merge two fields in document using mongodb -



merge two fields in document using mongodb -

below json, there way can merge multiple fields of same document.

"_id" : 1, "sem" : 1, "achieve" : [ 70, 87, 90 ]

i expecting output as

"_id" : 1, "sem" : [1,70, 87, 90], "achieve" : [ 70, 87, 90 ]

one of simple methods accomplish asking. can create loop documents of collection though. code below has 'stack' collection having 1 document, 1 mentioned.

doc = db.stack.findone(); var tmp = doc.sem; doc.sem = new array(); doc.sem.push(tmp); = 0; for(i = 0;i<doc.achieve.length;i++){ doc.sem.push(doc.achieve[i]); } db.stack.update({sem:1},doc);

mongodb

No comments:

Post a Comment