Skip to content

Instantly share code, notes, and snippets.

@claj
Created January 20, 2012 12:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save claj/1647271 to your computer and use it in GitHub Desktop.
Save claj/1647271 to your computer and use it in GitHub Desktop.
create mongoId
(ns testoi)
;; http://api.mongodb.org/java/2.6.3/org/bson/types/ObjectId.html
testoi> (import 'org.bson.types.ObjectId)
org.bson.types.ObjectId
testoi> (ObjectId. "d1700430f92f194fad7ce85a")
#<ObjectId d1700430f92f194fad7ce85a>
;;massageToObjectId seems to be more allowing on what it receives, but still picky
testoi> (ObjectId/massageToObjectId "d1700430f92f194fad7ce85a")
#<ObjectId d1700430f92f194fad7ce85a>
testoi> (ObjectId/massageToObjectId "aaaabbbbccccddddeeeeffff0000")
nil
;; because this is not valid according to the oi schema
;; A globally unique identifier for objects.
;; Consists of 12 bytes, divided as follows:
;; 0-3 time (4b)
;; 4-5 machine
;; 7-8 pid
;; 9-11 inc
;;or something.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment