Why this code return to me a dublicated docs?

const results = await Models.NFTs.aggregate([])

      .lookup({

        as: "creators.minter",

        from: "users",

        let: { minter: "$creators.minter", lazy_minter: "$lazy_mint_creator" },

        pipeline: [

          {

            $match: {

              $expr: {

                $or: [

                  { $in: ["$$minter", "$wallets"] },

                  { $in: ["$$lazy_minter", "$wallets"] },

                ],

              },

            },

          },

          {

            $project: { _id: 1, profile: 1, name: 1 },

          },

        ],

      })

      .unwind("creators.minter")

      .sort({ _id: -1 })

      .project({

        _id: 1,

        nft_id: 1,

        creators: 1,

        editions: 1,

        name: 1,

        listing: 1,

        url: 1,

      })

the result:

"data":[
   {
      "_id":"62ba8e36cc78e90041e3829c",
      "creators":{
         
      },
      "editions":{
         
      },
      "name":"fgfg",
      "listing":{
         
      },
      "url":"link"
   },
   {
      "_id":"62ba8e36cc78e90041e3829c",
      "creators":{
         
      },
      "editions":{
         
      },
      "name":"fgfg",
      "listing":{
         
      },
      "url":"link"
   },
   {
      "_id":"62ba8e36cc78e90041e3829c",
      "creators":{
         
      },
      "editions":{
         
      },
      "name":"fgfg",
      "listing":{
         
      },
      "url":"link"
   }
]

If you gave me more detailed documents, I can find a more accurate reason, but if you look at it simply, it seems to be coming out because of $unwind.

Refer to the example of a URL.

2 Likes

Thanks, I solve it.
I just used “$unwind” after “$sort”

1 Like

I found out thanks to you.
Have a nice day :smiley:

1 Like

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.