How can I add a two column unique id to the mongodb in a meteor app?

后端 未结 4 1078
滥情空心
滥情空心 2020-12-08 03:15

I am trying to create a two column unique index on the underlying mongodb in a meteor app and having trouble. I can\'t find anything in the meteor docs. I have tried from

4条回答
  •  星月不相逢
    2020-12-08 03:26

    Actually why not use upsert on the server with a Meteor.method and you could also send also track it with a ts: // Server Only

    Meteor.methods({
     add_only_once = function(id1,id2){
       SomeCollection.update(
         {first_id:id1,another_id:id2},{$set:{ts:Date.now()}},{upsert:True});
     }
    });
    

    // Client

    Meteor.call('add_only_once',doc1._id, doc2._id);
    

    // actual code running on server

    if(Meteor.is_server) {
        Meteor.methods({
            register_code: function (key,monitor) {
                 Codes.update({key:key},{$set:{ts:Date.now()}},{upsert:true});
            }
         ...
    

提交回复
热议问题