Having a bit of trouble getting my Meteor upsert function working. I am fairly (200 lines of code) new, and I\'m having a bit of trouble.
The collection keeps on having
Mongo.Collection#upsert(selector, modifier, [options], [callback])
ARGUMENTS
selector: Mongo Selector, Object ID, or String Specifies which documents to modify
modifier: Mongo Modifier Specifies how to modify the documents
callback: Function Optional. If present, called with an error object as the first argument and, if no error, the number of affected documents as the second.
OPTIONS: multi Boolean True to modify all matching documents; false to only modify one of the matching documents (the default).
https://docs.meteor.com/api/collections.html#Mongo-Collection-upsert
Try this:
values.update({"id":id},
{ $set: {
value: res.data['data']['last']['value'],
time: Date.now() // no need coma here
} },
{ upsert: true }
);
Figured it out through trial and error:
Values.upsert({
// Selector
source: "SourceOne",
currency: "USD"
}, {
// Modifier
$set: {
value: res.data['data']['last']['value'],
time: Date.now() // no comma needed here
}
});
The above doesn't work for IDs. This works for me (with the same syntax as update):
Values.upsert(id,
{
// Modifier
$set: {
value: res.data['data']['last']['value'],
time: Date.now() // no need coma here
}
}
);