[SOLVED] Case insensitive query in an aggregate / lookup query $eq

EDIT. I’ve just solved with a regular expression this way

{ $eq: [/"$owner"/, /ownerAddress/] },
{ $eq: ["$tokenId", playerId] },

Hello, I’ve a query “join” in the cloud functions using the lookup as explained in documentation. It’s working properly but it fails when it comes to do a string equality and the two strings are exadecimal with different upper / lower case.

This is part of the query

const ownerAddress = String(resultCardOwner.get("owner")).toUpperCase();

      const pipeline = [
          {
              match: {
                $expr: {
                     $and: [
                        { $eq: ["$owner", ownerAddress] },
                        { $eq: ["$tokenId", cardId] },

                     ],
                },
              },
          },
          {
            lookup: {
              from: "OtherCollection",
              localField: "owner",
              foreignField: "owner",
              as: "other",
            },
          },
.... other code

I’d like to bring all the strings to lower or upper case, and I think that I should do it also in the $eq expression, but I can’t find the right syntax.

Here

{ $eq: ["$owner", ownerAddress] },
{ $eq: ["$tokenId", playerId] },

and here ( I think)

  localField: "owner",
   foreignField: "owner",

I’ve tried with this

{ $eq: ["$toUpper": "$owner", ownerAddress] },
{ $eq: ["$tokenId", playerId] },

but it doesn’t compile.

Any suggestion? Thank you


1 Like