Generates new MongoDB Document ID's (also known as BSON ObjectID's) or validates existing ones.
A BSON ObjectID is a 12 byte binary string that is built up as follows:
- a 4-byte value representing the seconds since the Unix epoch,
- a 3-byte machine identifier,
- a 2-byte process id, and
- a 3-byte counter, starting with a random value.
However, this transformer will validate/generate its 24 character hexadecimal string equivalent.
Why use this transformer?
Although FME's MongoDB writer will generate MongoDB ID's automatically, there might be a case where you want to create documents that reference other documents by ObjectID. Therefore, you would need to generate an ID in advance, that will be written to the mongodb_id attribute. Note that you should rename this attribute (to anything you like) on the document feature if it uses this ObjectID as a foreign key (i.e. the "child"). Otherwise, the writer uses the ObjectID on both the "parent" and the "child" document as a primary key, which will fail.
- Also available on FME Hub for convenient installation.
- This transformer uses the Node.js abilities of the JavaScriptCaller, which currently is a beta feature of FME.
- There are no dependencies, because the code to generate the ObjectID's has been embedded. The original code can be found here.
- Released under GNU General Public License v3.0.
- If you notice a bug or desire a new feature, please contact me. Or make a pull request!
- This FME workspace is used for testing and provides some examples.
Operation Mode
When set to Generate, the transformer will create new MongoDB ObjectID's and store them in the mongodb_id attribute. If the attribute exists, it will be overwritten (!).
When set to Validate, the transformer assumes that the mongodb_id attribute exists and tries to validate it (see Overview). No ObjectID's will be created or overwritten in this mode. If a feature has an invalid ObjectID, it will be output through the Rejected port. The failure reason will be stored in the attribute mongodb_id_error.