0

My initial one of the document in a collection will be:

{
Canditate:"Clark weg",
Location:"California",
Education:"Graguate"
Match_Tasks:[]
}

I am getting response as a iteration in my code like: 1 st iteration response:

{
Asignee:"[email protected]",
Task_ID:"ObjectID_(2)"
}

After the 1st iteration response, My updated document is like:

{
Canditate:"Clark weg",
Location:"California",
Education:"Graguate"
Match_Tasks:[{Asignee:"[email protected]", 
        Task_ID's:
            [
            {ID:"ObjectID_(2)"}
            ]
        }
}

2 nd iteration response:

{
Asignee:"[email protected]",
Task_ID:"ObjectID_(3)"
}

My updated document is like:

{
Canditate:"Clark weg",
Location:"California",
Education:"Graguate"
Match_Tasks:[{Asignee:"[email protected]", 
        Task_ID's:
            [
            {ID:"ObjectID_(2)"}
            ]
        },
{Asignee:"[email protected]", 
        Task_ID's:
            [
            {ID:"ObjectID_(3)"}
            ]
        }
}

3 rd and 4th reponses: Third response:

{
Asignee:"[email protected]",
Task_ID:"ObjectID_(1)"
}

Fourth response:

{
Asignee:"[email protected]",
Task_ID:"ObjectID_(2)"
}

My updated document after my 3 rd and 4 th response:

{
Canditate:"Clark weg",
Location:"California",
Education:"Graduate"
Match_Tasks:[{Asignee:"[email protected]", 
        Task_ID's:
            [
            {ID:"ObjectID_(1)"},
            {ID:"ObjectID_(2)"}
            ]
        },
        {{Asignee:"[email protected]", 
        Task_ID's:
            [
            {ID:"ObjectID_(3)"},
            {ID:"ObjectID_(2)"}
            ]
        }
}

I am trying with the pymongo code:

aggregate([{"$match":{"Canditate":"Clark weg"}},{"$set":{"Match_Tasks":{
                                        "$map": {
                                    "input": "$Match_Tasks",
                                        "as": "Match_Tasks",
                                        "in": 
                                                        {"$cond":[{"$eq":["$Match_Tasks.Asignee",Asignee]},
                                                        {"$push":{"Match_Tasks.$.Task_ID's":{"$ID":Task_ID}}},
                                                        {"$push":{"Match_Tasks":{"Asignee":email,"Task_ID's":[{"$ID":Task_ID}]}}}]}}}} }])
2
  • One option here is to use an aggregation pipeline with a $merge step at the end Commented Jun 24, 2022 at 20:46
  • I have posted my query, I have tried but getting error:"set" has no attribute push.Could you please help me? Commented Jun 27, 2022 at 4:24

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.