OPTIONS

_hashBSONElement

Description

_hashBSONElement

New in version 2.4.

An internal command that computes the MD5 hash of a BSON element. The _hashBSONElement command returns 8 bytes from the 16 byte MD5 hash.

The _hashBSONElement command has the following form:

db.runCommand({ _hashBSONElement: <key> , seed: <seed> })

The _hashBSONElement command has the following fields:

Field Type Description
key BSONElement The BSON element to hash.
seed integer A seed used when computing the hash.

Note

_hashBSONElement is an internal command that is not enabled by default. _hashBSONElement must be enabled by using --setParameter enableTestCommands=1 on the mongod command line. _hashBSONElement cannot be enabled during run-time.

Output

The _hashBSONElement command returns a document that holds the following fields:

_hashBSONElement.key

The original BSON element.

_hashBSONElement.seed

The seed used for the hash, defaults to 0.

_hashBSONElement.out

The decimal result of the hash.

_hashBSONElement.ok

Holds the 1 if the function returns successfully, and 0 if the operation encountered an error.

Example

Invoke a mongod instance with test commands enabled:

mongod --setParameter enableTestCommands=1

Run the following to compute the hash of an ISODate string:

db.runCommand({_hashBSONElement: ISODate("2013-02-12T22:12:57.211Z")})

The command returns the following document:

{
  "key" : ISODate("2013-02-12T22:12:57.211Z"),
  "seed" : 0,
  "out" : NumberLong("-4185544074338741873"),
  "ok" : 1
}

Run the following to hash the same ISODate string but this time to specify a seed value:

db.runCommand({_hashBSONElement: ISODate("2013-02-12T22:12:57.211Z"), seed:2013})

The command returns the following document:

{
  "key" : ISODate("2013-02-12T22:12:57.211Z"),
  "seed" : 2013,
  "out" : NumberLong("7845924651247493302"),
  "ok" : 1
}