Is there a way to send hex of binary value instead of base64 to BinData() in mongo ?
Asked
Active
Viewed 6,441 times
4
-
I'm not sure I understand - you want to convert it to hex after retrieving it? You have it in hex and need base64 to save it? Can you edit the question with an example? – wdberkeley Mar 10 '15 at 17:00
-
@wdberkeley, for example use `BinData(0,"0565AF71")` instead of `BinData(0,"BWWvcQ==")` – Hamid Mamdoohi Mar 10 '15 at 18:01
-
So you want to transform hex data into base64. I don't think there are helpers for that in the shell - you ought to transition to using a driver, like the Node.js driver, where you can use a library to do the conversion. – wdberkeley Mar 10 '15 at 18:11
3 Answers
7
HexData(3,"00112233445566778899aabbccddeeff")
or
UUID("00112233445566778899aabbccddeeff")
will both result to:
BinData(3,"ABEiM0RVZneImaq7zN3u/w==")
And the other way around:
BinData(3,"ABEiM0RVZneImaq7zN3u/w==").hex()
will result:
00112233445566778899aabbccddeeff

JSON C11
- 11,272
- 7
- 78
- 65

Doron Levari
- 566
- 4
- 4
0
Only Use HexData(subtype, hexstr)

JSON C11
- 11,272
- 7
- 78
- 65

Hamid Mamdoohi
- 134
- 1
- 9
-
1While this code may solve the question, [including an explanation](https://meta.stackoverflow.com/questions/392712/explaining-entirely-code-based-answers) of how and why this solves the problem would really help to improve the quality of your post, and probably result in more up-votes. Remember that you are answering the question for readers in the future, not just the person asking now. Please **edit** your answer to add explanations and give an indication of what limitations and assumptions apply. – Alexandre B. Apr 29 '20 at 09:06
0
If your mongodb driver uses javascript, then you should try BinData(3,"ABEiM0RVZneImaq7zN3u/w==").toString('hex');
I didn't find another way, because there is no hex();
function in JS

asipes
- 1
- 1