Created On: April 07, 2022, Last Updated On: April 07, 2022

Mongo Examples

Public

By Ozzie Ghani3 new




Example 1


from bson import ObjectId
import uuid

print(uuid.uuid4().hex)


def oid_to_string(oid):
    return str(oid)


def string_to_oid(s):
    return ObjectId(s)


def getNewUUIDhex(length):

    if length:
        _uuid = str(uuid.uuid4().hex[:length])
    else:
        _uuid = str(uuid.uuid4().hex)

    return _uuid


_uuid = getNewUUIDhex(24)
print(_uuid)
print(string_to_oid(_uuid))