I am trying to copy selected fields from collection 'a' to collection 'b'. I would like to set multiple fields on b based on whether they exist in a. i.e If the field dosen't exist in 'a; then I don't want to set it in 'b'.
This is what I'm trying
b.update_one(
{"_id": xyz},
{"$set": {"name": a['name'],
"lastname": a.get('lastname', None)}})
This gives me None is lastname doesn't exist. I don't want lastname to be updated at all if there is not lastname in 'a'. Is there any other alternative apart from using 2 set statements?