Closed ekanna closed 13 years ago
At present i am using below functions to remove _ID from the retrieved array:
function myArr (arr){
var x = arr.length;
var z = [];
for(var y=0; y<x; y++){
z[y] = myObj(arr[y]);
}
return z;
}
function myObj (obj){
var s = Object.keys(obj).slice(1);
var i = 0;
var j = s.length;
var o = {};
for (i=0; i<j; i++){
o[s[i]] = obj[s[i]];
}
return o;
}
But looking for a better way todo this. As it may not the optimal way to do. I am looking for some in built options available in Mongous to remove _ID from the result array.
Oh my! This is a javascript issue. I am very pleased to tell you that you can delete any property/attribute from any object in javascript simply by...
var obj = { hello: "world", nice: "to see you" }; delete obj.nice;
And now the object is
{hello:"world"}
So all you have to do is:
delete obj['_id'];
fyi. I don't like _id either, but it is how Mongo keeps tabs on things - go read MongoDB's documentation on IDs for more information. Also, this was a javascript question, not an issue with mongous (or MongoDB) - so please make sure you ask any next questions in the appropriate location.
Enjoy Mongous!
Thanks a lot!
Hi all,
Is there any easy way to remove the _ID from results?
Thanks koti