This one gives you more control over which object gets updated. You have to pass it an index of the object that you want to update. The result will always be an array and the index will start from 0 of course

db.find({type: "Human"})
    .then((Data) => {
        Data.result[1].username = "Fizz"

To explain a bit more, This will update the second element of the results of {type: "Human"} from .find()

You can also use updateAll() here but that might be slow when you just want to update one object because that method has to iterate over each result element to make sure everything gets updated.

results matching ""

    No results matching ""