[SERVER-3168] add some convenient methods for BinData and UUID Created: 30/May/11  Updated: 12/Jul/16  Resolved: 31/May/11

Status: Closed
Project: Core Server
Component/s: None
Affects Version/s: None
Fix Version/s: 1.9.1

Type: Improvement Priority: Minor - P4
Reporter: Antoine Girbal Assignee: Antoine Girbal
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
related to SERVER-3153 The mongo shell needs better support ... Closed
is related to SERVER-1201 shell support for UUID (binary subtyp... Closed
Participants:

 Description   

MongoDB shell version: 1.9.1-pre-
> help misc
b = new BinData(subtype,base64str) create a BSON BinData value
b.subtype() the BinData subtype (0..255)
b.length() length of the BinData data in bytes
b.hex() the data as a hex encoded string
b.base64() the data as a base 64 encoded string
b.toString()

b = HexData(subtype,hexstr) create a BSON BinData value from a hex string
b = UUID(hexstr) create a BSON BinData value of UUID subtype
b = MD5(hexstr) create a BSON BinData value of MD5 subtype

o = new ObjectId() create a new ObjectId
o.getTimestamp() return timestamp derived from first 32 bits of the OID
o.isObjectId()
o.toString()
o.equals(otherid)



 Comments   
Comment by auto [ 22/Jun/11 ]

Author:

{u'login': u'agirbal', u'name': u'agirbal', u'email': u'antoine@10gen.com'}

Message: SERVER-3168: Fixed hexadecimal output, added tests
Branch: master
https://github.com/mongodb/mongo/commit/403b7aa8a28094fb4f541a86d8f89c0c794ef329

Comment by Antoine Girbal [ 16/Jun/11 ]

many thanks for report, I will fix that

Comment by Mark Lewis [ 16/Jun/11 ]

I just tested the 2011-06-15 nightly, and the new .hex() method, while convenient, seems to have a bug where it drops zeroes, leading to incorrect results

If I take a BinData(3, "OEJTfmD8twzaj/LPKLIVkA==") and convert to hex, I get the following (Correct output, then Mongo output):

38 42 53 7e 60 fc b7 0c da 8f f2 cf 28 b2 15 90
38 42 53 7e 60 fc b7 c da 8f f2 cf 28 b2 15 90

(spaces were added to separate the bytes, note the missing 0 on the most-significant byte in the UUID).

This is also apparent because round-tripping the value to/from hex changes the value:

> var x = new BinData(3, "OEJTfmD8twzaj/LPKLIVkA==")
> x == new HexData(3, x.hex())
false
> new HexData(3, x.hex())
BinData(3,"OEJTfmD8t82o/yzyiyFZ")

Comment by auto [ 31/May/11 ]

Author:

{u'login': u'agirbal', u'name': u'agirbal', u'email': u'antoine@10gen.com'}

Message: SERVER-3168: finished MD5 and HexData for v8
Branch: master
https://github.com/mongodb/mongo/commit/13364b16f47fb83b3cc5b9946fd1c9e2b57ae7eb

Comment by auto [ 30/May/11 ]

Author:

{u'login': u'agirbal', u'name': u'agirbal', u'email': u'antoine@10gen.com'}

Message: SERVER-3168: added UUID type and method. Fixed conversion to BSON.
Branch: master
https://github.com/mongodb/mongo/commit/8aeaf8d850d65c934cc5269e4c78a0eb138e9183

Comment by auto [ 30/May/11 ]

Author:

{u'login': u'agirbal', u'name': u'agirbal', u'email': u'antoine@10gen.com'}

Message: SERVER-3168: methods implemented for BinData
Branch: master
https://github.com/mongodb/mongo/commit/e371c76ccac4f166b7f267114526a6c8b073f5de

Comment by auto [ 30/May/11 ]

Author:

{u'login': u'agirbal', u'name': u'agirbal', u'email': u'antoine@10gen.com'}

Message: SERVER-3168: for v8, added base64() method and now the binary data is stored in internal field, cleaner
Branch: master
https://github.com/mongodb/mongo/commit/1eb57466fc10c3538e1b1585fc709451909af359

Comment by auto [ 30/May/11 ]

Author:

{u'login': u'agirbal', u'name': u'agirbal', u'email': u'antoine@10gen.com'}

Message: SERVER-3168: added length() and subtype(). Moved methods from SM layer to utils.js
Branch: master
https://github.com/mongodb/mongo/commit/21def6cf9438f77e54163c9109325d3f880fc6e6

Generated at Thu Feb 08 03:02:16 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.