流星更新 [英] Meteor upsert equivalent

查看:106
本文介绍了流星更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

upsert命令将在Meteor中实施多久?

How soon will the upsert command be implemented in Meteor?

同时,做同一件事的最好方法是什么?

And, what is the best way to do the same thing in the mean time?

此刻我正在做的事情是这样的

Something like this is what I'm doing at the moment:

if typeof ( item = Items.findOne({title:'Foo'}) ) == 'undefined'
    item = Items.insert({title:'Foo'})
else
    Items.update(item._id, {$set: {title:'Foo'}})
# do something with item

推荐答案

upsert命令将在Meteor中实施多久?

How soon will the upsert command be implemented in Meteor?

更新: @ Thomas4019 指出现在支持upsert:

v0.6.6

添加upsert支持.Collection.update现在支持{upsert:true}选项.此外,添加Collection.upsert方法,该方法将返回新插入的对象ID(如果适用)."

"Add upsert support. Collection.update now supports the {upsert: true} option. Additionally, add a Collection.upsert method which returns the newly inserted object id if applicable."

来源: History.md

使用文档: http://docs.meteor.com/#upsert

-原始答案如下-

Trello流星路线图上有一张卡片,您可以对其进行投票以表明其对您的重要性: https: //trello.com/c/C91INHmj

There is a card on the Trello Meteor Roadmap which you can vote on to indicate its importance to you: https://trello.com/c/C91INHmj

当前位于以后"列表中,这意味着除非获得大量投票,否则要过一段时间才能实现.

It is currently in the "Later" list which means it will be a while before it is implemented unless it receives a lot of votes.

要注意的另一件重要事情是,由于流星是开源的,因此您可以自己进行必要的更改并提交.

The other important thing to note is that since meteor is open-source, you could implement the necessary changes yourself and submit back.

在同一时间做同一件事的最好方法是什么?

What is the best way to do the same thing in the mean time?

有几种解决方案,但是如果没有更多的设计知识,就无法说出最适合您的用例的情况.

There are several solutions but which is most appropriate for your use-case is impossible to tell without more knowledge of your design.

  1. 照原样使用代码,向集合中添加唯一索引,并在出现重复键错误时/在出现重复键错误时进行处理

  1. Use the code as is, add an unique index to the collection, and handle the duplicate key error if/when it arises

更改设计以实现显式的乐观并发.

Change design to implement explicit optimistic concurrency.

这两个解决方案的核心是相同的,可以很好地处理错误情况. #1更易于实现. #2在处理乐观并发方面提供了更大的灵活性.

The core of both of these solutions is the same, gracefully handle the error case. #1 is easier to implement. #2 allows for greater flexibility in how the optimistic concurrency is handled.

这篇关于流星更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆