Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

.update() not updating correctly. How can I overwrite but keep same ID? #320

Closed
bastianpedersen opened this issue Sep 30, 2020 · 1 comment

Comments

@bastianpedersen
Copy link

Database contains:

{
"_id": "5f731c9171320635dc9c126c",
"name": "Kragerø Grand Prix 2020",
"description": "Kragerø Sjakklubb inviterer nok en gang til Kragerø GP. Dette for tiende gang! Det er satt en grense på 100 spillere, så meld deg på før det er for sent!",
"place": "Kragerø Sportell",
"group": "Individuell turnering",
"time": "90 minutter + 30 sekunder pr. trekk",
"date": "14. - 17. okt 20",
"organizer": "Kragerø Sjakklubb",
"arbiter": "FA Hans Jørgen Hoem",
"price": "550 kr for FIDE under 2150. IM/GM gratis samt WFM.",
"players": [
"Hans Asbjørn"
]
}

When I call .update() like this:
const updated = await tournaments.update( { _id: id }, { $set: value }, { overwrite: true }, );

where value is:

{
"name": "Kragerø Grand Prix 2020",
"description": "Kragerø Sjakklubb inviterer nok en gang til Kragerø GP. Dette for tiende gang! Det er satt en grense på 100 spillere, så meld deg på før det er for sent!",
"time": "90 minutter + 30 sekunder pr. trekk",
"group": "Individuell turnering",
"place": "Kragerø Sportell",
"date": "14. - 17. okt 20",
"organizer": "Kragerø Sjakklubb",
"arbiter": "FA Hans Jørgen Hoem",
"price": "550 kr for FIDE under 2150. IM/GM gratis samt WFM."
}

notice that the "players" array is deleted.

But, when I try to update my database on that document with the specific ID, it doesn't remove the players object. How can I just overwrite the document but keep the same ID?

@bastianpedersen bastianpedersen changed the title .update not updating correctly .update() not updating correctly. How can I overwrite but keep same ID? Sep 30, 2020
@bastianpedersen
Copy link
Author

This works: tournaments.findOneAndUpdate({ _id: id }, value, { replaceOne: true });

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant