How to get binary field from existing mongo db doc?
In the MongoDB console, if I find a record for the selection, I get the following:
{_id:ObjectId("1234"),"cover_data" : BinData(2,"ozkAAP/Y/+AAEEpGSUYAAQEBAJYAlgAA/+IFpElDQ19QUk9GSUxFAAEBAAAFlGFwcGwCIAAAbW50clJHQiBYWVogB9kAAgAZAAsAGgALYWNzcEFQUEwAAAAAYXBwbAAAAAAAAAAAAAAAAAAAAAAAAPbWAAEAAAA ..... )
In python on our web server, when we find with pymongo, it receives this field as binary and json_pickle seems to automatically turn it into base64 and, alas, the image looks great when sent back to the client. When I compare the generated base64 with the node.js mongo driver, it is completely different and does not display the image correctly.
Here is the code for node.JS:
cb = function(comp) { thumb_buffer = new Buffer(comp.thumbnail_data.value(),'binary'); comp.thumbnail_data = thumb_buffer.toString('base64'); }
In the examples and test cases here: https://github.com/christkv/node-mongodb-native I do not see any example of what I'm trying to do. It seems that there are BSON and BinaryParser deserializers that are used with the whole BSON object. I tried this for only one field and got segmentation errors.
Running the list of things I tried:
mongo_compositions.find {_id:{$in:ids}},{},(err,compositions) -> for comp in compositions do(comp) => thumb_buffer = comp.thumbnail_data.value(true) test_buffer = Binary(thumb_buffer) console.log test_buffer console.log test_buffer.toString('base64')
source share