I'm currently making an achievement system and trying to save it in two collections.
One collection that contains the name and id,
and the other collections with users and their progress.

I've been looking at Aggregation, and on $lookup, and made some progress, but I'm not sure what would be necessary to do to make the desired output that I would like.

If the user exists in achievements, get the progress value and their userid with the collection, if not, make progress value to 0.

Wouldnt this be some kind of joining in for example Mysql?, how would this be in MongoDB?

variable `userid = 33;`

attempt:

```
db.getCollection('achievements').aggregate([
   {
     $lookup:
       {
         from: "achievement_users",
         localField: "id",
         foreignField: "id",
         as: "inventory_docs"
       }
  }
])

```

achievement schema:

```
{
    "name" : "testing",
    "id" : 1,
    "max" : 12,
},

{
    "name" : "testing2",
    "id" : 2,
    "max" : 12,

}

```

achievement user:

```
{
    "userid" : 33,
    "id" : 1,
    progress: 1,
},
 {
        "userid" : 446,
        "id" : 1,
        progress: 1,
    }

```

Desired output:

```
{
name: "testing",
id: 1,
userid: 33,
progress: 1,
    max : 12,

},
{
name: "testing2",
id: 2,
progress: 0,
    max : 12,

},

```

EDIT:

I need all achievements that the user have done, and not have done ( not have done = progress = 0).

it may be achievements that the user havent done. i want them listed too, but to have the progress value of 0.

update 2:
Also need it to give me results while there are no match in achievement\_users for that spesific userid.