本文介绍了如何使用流星Upsert的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
让我的Meteor upsert功能正常工作有点麻烦.我是相当(200行代码)的新手,但遇到了一些麻烦.
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.
该集合将继续插入其他行,而不仅仅是更新.我花了30分钟的时间进行谷歌搜索,但找不到任何我能理解的示例.
The collection keeps on having additional rows inserted, rather than just updating. I spend the past 30 minutes googling, but I can't find any examples I can understand.
这是我的代码:
Values.upsert(
{
// Selector
source: "SourceOne",
currency: "USD"
},
{
// Modifier
value: res.data['data']['last']['value'],
time: Date.now(),
}
);
我也尝试过
if(Values.find(
{},{fields: {'source':"SourceOne", 'currency': "USD"}}
)) {
Values.update(
{
source: "SourceOne",
currency: "USD"
},
{
value: res.data['data']['last']['value'],
time: Date.now()
}
);
} else {
console.log('blah');
Values.insert({
source: "SourceOne",
currency: "USD",
value: res.data['data']['last']['value'],
time: Date.now()
});
}
仍然似乎无法弄清楚.
推荐答案
通过反复试验找出了答案:
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
}
});
这篇关于如何使用流星Upsert的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!