Is there any way providing exact match in MongoDB?

There is a document like follows in my collection called memory.

db.memory.insert(
    {
        "bgtime":"bgtime",
        "edtime":"edtime",
        "key1":"val1",
        "key2":"val2",
        "some_keys_I_dont_know":"val3"
    }
)

Then I use the shell command as follows to achieve the goal that insert the document when the filtered document is not found, and update the document when the filtered document is found:

db.memory.update(
    {
        "bgtime":{$exists:true},
        "edtime":{$exists:true},
        "key1":"val1",
        "key2":"val2"
    },
    {
        $set:
        {
            "bgtime":"bgtime",
            "edtime":"edtime",
            "key1":"val1",
            "key2":"val2"
        }
    },
    {
        $upsert:true
    })

I matched the document that I inserted in the beginning, this is not what i want, i want to only match the document like this:

{
    "bgtime":"bgtime",
    "edtime":"edtime",
    "key1":"val1",
    "key2":"val2"
}

Is there any way or operator I can use when I find?

Notes that I can not use the expression like <“key3”:{$exists:false}> because I use MongoDB in C++, and I use map to insert kvp, so actually i don’t key’s name. Here is my code:

for(const auto& item :mapMemory)
 {
    find_doc << item.first << item.second;
    update_doc << item.first << item.second;
 }

Thanks.