+# MongoDB Object ID representation.
+#
+# For ObjectIDs, MongoDB uses the `ObjectId("hash")` notation.
+# This notation is replicated by the `to_s` service.
+#
+# Since the MongoDB notation is not JSON complient, the mongoc wrapper uses
+# a JSON based notation like `{"$oid": "hash"}`.
+# This is the notation returned by the `to_json` service.
+private class MongoObjectId
+
+ var native: BSONObjectId
+
+ # The unique ID as an MongoDB Object ID string.
+ fun id: String do return native.id
+
+ # Internal JSON representation of this Object ID.
+ #
+ # Something like `{"$oid": "5578e5dcf344225cc2378051"}`.
+ fun to_json: JsonObject do
+ var obj = new JsonObject
+ obj["$oid"] = id
+ return obj
+ end
+
+ # Formatted as `ObjectId("5578e5dcf344225cc2378051")`
+ redef fun to_s do return "ObjectId({id})"
+end
+