Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
253 views
in Technique[技术] by (71.8m points)

mongodb - Cannot get documents with an $all in pipeline $lookup

I have this collection "user" :

[{
  "_id": {
    "$oid": "5f7b21afd3ad8808032490de"
  },
  "role": "admin",
  "email": "[email protected]",
  "username": "Test",
  "status": "active",
  "following": [
    {
      "$oid": "5fc767b09ae62d40ba09624f"
    }
  ],
},{
  "_id": {
    "$oid": "5fc767b09ae62d40ba09624f"
  },
  "role": "streamer",
  "email": "[email protected]",
  "username": "Test_2",
  "status": "active",
  "following": []
}]

I am trying to get the follower of each user, this is what I've began but the followers is empty array :

{
  $lookup: {
    from: 'user',
    let: { userId: '$_id'},
    pipeline: [
      {
        $match: {
          following: {
            $all: ['$$userId']
          }
        }
      }
    ],
    as: 'followers'
  }
}

Do you know what's wrong in my code ?

Thank you

question from:https://stackoverflow.com/questions/66051587/cannot-get-documents-with-an-all-in-pipeline-lookup

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...