Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Well, according to <a href="https://stackoverflow.com/questions/13206015/meteor-upsert-equivalent">this answer</a> Meteor $upsert flag is still in enhancement list and seems to be added in stable branch after 1.0 release.</p> <p>So the first way is how it was said to add an unique index:</p> <p>All the implementation ways are <a href="https://stackoverflow.com/questions/10167604/how-can-i-add-a-two-column-unique-id-to-the-mongodb-in-a-meteor-app">listed here</a>. I would recommend you to use native mongo indexes, not a code implementation. </p> <p>The optimistic concurrency way is much more complicated according to no transactions in MongoDB.</p> <p>Here comes my implementation of it(be careful, might be buggy))):</p> <pre><code>var result_callback = function(_id) { // callback to call on successfull insert made } var $set = {stage_id: xxxx, entrant_id: xxxx}; var created_at = Date.now().toFixed(); var $insert = _.extend({}, $set, {created_at: created_at}); Scores.insert($insert, function(error, _id) { if (error) { //handle it return; } var entries = Scores.find($set, {sort: {created_at: -1}}).fetch() if (entries.length &gt; 1) { var duplicates = entries.splice(0, entries.length - 1); var duplicate_ids = _.map(duplicates, function(entry) { return entry._id; }); Scores.remove({_id: {$in: duplicate_ids}}) Scores.update(entries[0]._id, $set, function(error) { if (error) { // handle it } else { result_callback(entries[0]._id) } }) } else { result_callback(_id); } }); </code></pre> <p>Hope this will give you some good ideas)</p> <p><em>Sorry, previous version of my answer was completely incorrect.</em></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload