Reputation: 238
I have a JSON object that is imported by the client (imported as XLSX and converted to JSON).
Every JSON object has a reference and other several fields that get inserted in my collection.
What I'm trying to do is whenever a client imports a JSON object with a reference that is already in one of my collection documents I want to update that document with the updated fields and new ones imported by the client.
This is how I'm trying to reach it:
let keys = Object.keys(json.data[0]);
let values = Object.values(json.data[0]);
Adverts.update({'reference': json.data[0].reference}, {$set: {keys: values}}, {upsert: true});
I've checked the docs and other answers, seems like with upsert and $set is the way to go, but I don't know what I'm doing wrong.
Thanks.
Upvotes: 0
Views: 86
Reputation: 14998
keys
and values
are arrays, you can't do this:
... {$set: {keys: values}}
...
Instead try this:
Adverts.update({'reference': json.data[0].reference},
{$set: json.data[0] }, {upsert: true});
Upvotes: 1