Go MongoDB query with a limit in an $or statement

Viewed 30

So I have this mongoDB filter in my Go code and I need to add a limit for some matching cases.

Basically if the id matches for any of the partners in the or case I have to check the other partners id and if I get 5 with the same id (of the other partner) I have to skip them.

I tried to look for something like this, but could not find anything. I don't even know if it's possible to do on the db side.

If anyone has an idea of how to implement this I would really appreciate it.

Here is the filter I am currently using:

    match := bson.D{
        {"unlocked", false},
        {"deletedAt", nil},
        {"$or", []bson.M{
            {
                "partnerA.id":               id,
                "partnerA.looksInteresting": false,
            },
            {
                "partnerB.id":               id,
                "partnerB.looksInteresting": false,
            },
        }},
    }
0 Answers
Related