Unable to search documents in atlas by UUID


What is the proper filter document to be used in mongodb atlas to filter documents in a collection based on a field of type UUID? I have been unable to find any documentation or examples on this.


Use $uuid instead of UUID().

{“id”:{"$uuid": “2a7c560c-bb1a-466a-84f8-94c98e273179”}}

Not working. =/

(BadValue) unknown operator: $uuid

Type issues like your uuid problem are hard(1) to find without real non-redacted example documents and real non-redacted code.

Please share documents and code.

hard(1) - because sometimes, the data is stored as the string representation and the query is done with the binary data or the other way around, it is store in the binary format and the query is done using the string representation.

Hi, @steevej! Thank you for your reply and explanation!

Here is my document:

    "_id": {
        "$binary": {
            "base64": "ZJZwgzlEQeyU0wJ7Uhhtuw==",
            "subType": "04"

And here is my Trigger code:

exports = async function (changeEvent) {
    const collection = context.services

    const doc = await collection.findOne({
        "_id": { $uuid: "64967083-3944-41EC-94D3-027B52186DBB" }

    return doc;

It throws: (BadValue) unknown operator: $uuid

Here is a print of what i am trying to do:

Thank you again!

Take a look at $convert.

I am not sure it could be used to convert to UUID, but it is where I would start my quest.