1

https://mongoplayground.net/p/MlQFd6J4rZc

Products.aggregate({
    $match: {
        $or: [
            { '_id': {$regex: queryRegex } },
            { 'name': {$regex: queryRegex } },
        ]
    },
    {
    $addFields: {
      favorite: {
        $cond: [
          {
            $in: [
              'xxx',
              '$favoritedBy'
            ]
          },
          true,
          false
        ]
      }
    }
  
})

Adding the $addFields portion broke the code. I am not sure why. It's working on the mongoplayground example I set up. Is there any reason for this? removing $addFields removes the error, but I should be able to create a new field, so I am confused as to what's going on.

Mongoose is version 5.11.12, so it's not caused by the version number, I think.

Error: Arguments must be aggregate pipeline operators at Aggregate.append

useNewUrlParser was set to true.

Sayaman
  • 1,145
  • 4
  • 14
  • 35

0 Answers0