'how to replaceOne document in MongoDb with Mongo database command

We have requirement to execute replaceOne operation with db.runCommand()

I checked list of commands from here, but i haven't found any command to replace one document.

Can someone please suggest us whether this is possible or not?



Solution 1:[1]

We can use update command to replace one document. Refer update for more details.

Sample replace command

{
    'update': 'collectionName',
    'updates': [
        {
            'q': {
                'age': '33'
            },
            'u': {
                'status': 'pass',
                'company': 'AK'
            }
        }
    ]
}

Refer update-with-a-replacement-document for more details

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1