question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Aggregate Raw not working when trying to `$match` on `_id` (needs to be an `ObjectId` but it's not a valid input)

See original GitHub issue

new aggregate raw support

@matthewmueller Do you guys know about any issue that the raw aggregation support is having? I’m trying to run a pipeline though it, which I know for a fact that is working because I wrote it and tested it at first on MongoDB Compass.

return this.prisma.user.aggregateRaw({
      pipeline: [
        {
          $match: {
            _id: id,
          },
        },
        {
          $project: {
            communityId: 1,
          },
        },
        {
          $lookup: {
            from: 'Community',
            localField: 'communityId',
            foreignField: '_id',
            as: 'community',
          },
        },
        {
          $project: {
            communityId: 0,
          },
        },
        {
          $unwind: {
            path: '$community',
          },
        },
        {
          $lookup: {
            from: 'CommunityNft',
            localField: 'community._id',
            foreignField: 'communityId',
            as: 'communityNft',
          },
        },
        {
          $unwind: {
            path: '$communityNft',
          },
        },
        {
          $lookup: {
            from: 'NftBenefit',
            localField: 'communityNft._id',
            foreignField: 'communityNftId',
            as: 'nftBenefits',
          },
        },
        {
          $lookup: {
            from: 'Voucher',
            localField: 'nftBenefits._id',
            foreignField: 'nftBenefitId',
            as: 'vouchers',
          },
        },
      ],
    });

This operation is returning an empty array.

_Originally posted by @pedrobrun in https://github.com/prisma/prisma/issues/6712#issuecomment-1227771299_

Issue Analytics

  • State:open
  • Created a year ago
  • Comments:14 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
Jolg42commented, Oct 11, 2022

Unfortunately no news, I’m not part of the team that will work on this. I can only say it’s on their radar, so they will pick this up one day, but they have to prioritize with other issues.

1reaction
pedrobruncommented, Aug 31, 2022

@Jolg42 ok, got it! Thanks for the update 😃 Prisma’s version was 4.2.1. Mongo’s locally installed version is 5.0.7, but the development db is hosted on Atlas. Tbh there’s no additional information. I had to migrate to Mongoose as I had some deadlines close and this was a core feature and I didn’t want to have to hit 4+ collections separately. Once this is sorted out I’ll probably move back to Prisma though.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Aggregate $match _id $eq $toObjectId not working - MongoDB
Using Compass 1.30.1, I was testing an aggregation and getting unexpected results. A $match was not working as expected.
Read more >
MongoDB, Aggregate $match not working on ObjectId
I want to filter and get the photo which belong to 1 specific user, based on their user_id. I don't understand what I...
Read more >
Raw database access (Reference) - Prisma
Learn how you can send raw SQL and MongoDB queries to your database using the raw() methods from the Prisma Client API.
Read more >
Troubleshoot your embedded application - Power BI
This article discusses some common issues you may encounter when embedding content from Power BI.
Read more >
JavaScript Developers Guide | Parse
If you want to retrieve objects that do not match any of several values you can ... in Mongo Aggregate Documentation will work...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found