I have a quite big collection of data, made by third parties, it contains a Bindata "package" column where plain ASCII is actually stored. I mean, they could have stored the text as string.
I have to export this collection in csv format, which works quite well with mongoexport, but the output contains the base64 encoded values for the "package" column. I need the actual text from that column, not BinData(0,\"NDYuN.....==")
.
What I've tried so far is update the collection with a new column "rawData", like this:
db.segments.find({"_id" : ObjectId("4fc79525f65181293930070b")}).forEach(function(data) {
db.segments.update(
{_id:data._id},
{$set:{ "rawData" : data.package.toString() }}
);
});
I've limited the find to just one document until I get it right. Unfortunately toString does not do the magic I expect.
Also, I've tried this:
db.segments.find({"_id" : ObjectId("4fc79525f65181293930070b")}).forEach(function(data){
data.package = new String(data.package);
db.segments.save(data);
});
The result was even worse.
If I read the document with php, $response = $db->execute('return db.segments.findOne()');
then print_r($response)
, I can validate that the data is properly stored, as base64.
I couldn't find a solution anywhere, perhaps because nobody ever needed to do something as stupid as this.