Skip to content

How to use UUID as _id #374

@GorillaGroddUK

Description

@GorillaGroddUK

I want to use UUID for the _id value, but I can't get Mongo to recognise the value.

I start by setting uuidRepresentation='standard' parameter when initiating the MongoClient connection.

In my schema I declare a UUID attribute; this seemed to have no effect:

uuid = fields.UUIDField(
	attribute='_id',
	default=uuid.uuid4,
	unique=True,
	)

Result: 
{
  "_id": {
    "$oid": "625aadba5d4a05bfa5c6b26b"
  },
}

Declaring the attribute as a string, the result is the same:

uuid = fields.StringField(
	attribute='_id',
	default=str(uuid.uuid4()),
	unique=True,
	)

Result: 
{
  "_id": {
    "$oid": "625aaad798ceb63062a2c15c"
  },
}

What am I doing wrong?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions