I have a large collection of data, created by third parties, there is a bindata "package" column, where plain ASCII actually stored I mean, they could store the text as a string.
I have to export this collection in CSV format, which works quite well with MongoEstApport, but Base has the base 64 encoded values for the "Package" column in output. I need actual text from that column, not The update is a new column "raw data" which I have tried so far, like: I have limited only one document till I get it properly. Unfortunately, toasting does not expect magic. Besides, I have tried to: The result was worse. If I If I read the document with HP, then execute I could not find a solution anywhere, maybe because anyone did something like this kind of stupid JavaScript BinData object , The binary data field is composed of a 32-bit integer length, subtype, and byte array. Back in the base 64 and hexadecimal presentations in JS, there is a prepared byte array with integer length. This means that after decoding the values, we want to touch the first four bytes. Here is an example using both options: And there is a small PHP script that I used to include some stability data: Based on the size of your data set, it would be better to convert binary fields into PHP, if you use Javascript. If you want to do this, then I definitely recommend performing the script through shell client instead of BinData (0, \ "NDYuN ..... ==") .
db.segments.find ({" _ Id ": ObjectId (" 4fc79525f65181293930070b "}}). Each (function (data) {Db.segments.update ({_id: data._id}, {$ set: {"rawData": data.package.toString ()}})}};
db.segments.find ({"_ id": ObjectId ("4fc79525f65181293930070b"}} .for each (function) {Data.package = new string (data package); db .segments.save (data);});
$ response = $ db-> ('return db.segments .findOne ()'); then
print_r ($ response) , I can validate that the data is stored properly, as base64.
base64 () and
Hex () are methods, which are high Yoga can help you to get a string of related formats. You have a few options to decode these values in text strings within JS:
// https://stackoverflow.com/a/3058974/162228 function decode_base64 {s} {var e = {}, i, K, v = [], r = ', w = String.fromCharCode; Var n = [[65,91], [97,123], [48,58], [43,44], [47,48]]; For (n) {for (i = n [z] [0]; i & lt; n [z] [1]; i ++) {v.push (w (i));}} For i = 0; (I = 0; i & lt; s.length; i + = 72) {var b = 0, c, x, l = 0, o = for i <64; i + +) {E [V] [i]] = i; S.substring (i, i 72+); (X = 0; x & lt; o.length; x ++) {c = e [o.charAt (x)]; B = (B & L; <6) + c; L + = 6; While (L> = 8) {r + = w ((B>> (L-8))% 256);}}} return r; } // https://stackoverflow.com/a/3745677/162228FunctionHex2A (hex) {var str = ''; (Var i = 0; i & lt; hex.length; i + = 2) str + = string. Lightcard (persicent (hex.Subert (i, 2), 16)); Return str; } Db.segments.find () ForEach (function (doc) {print (decode_base64 (doc.package.base64 ());}); Db.segments.find () .forEach (works (doctor) {print (hex2a (doc.package.hex ))}}};
db.eval () so that you do not lock the database with long running JS Do Function.
Comments
Post a Comment