2016-05-12 3 views
2

私は文書を挿入する流星法を持っています。そのドキュメントのidはurl拡張子の役割を果たします。ドキュメントが作成された後、同じ方法で電子メールを送信します。電子メールでは、URL拡張子へのリンクを含めたいと思います。どうやってやるの?流星ドキュメントから流星:メソッド内で挿入された_idを取得するにはどうすればよいですか?

//create a video 
Meteor.methods({ 
    createVideo: function(doc) { 
    Videos.insert({title: doc.title, userId: this.userId, date: new Date()}); 

    var emailData = { 
     message: "Click the link below to go to your video.", 
     buttontext: "View My Video", 
     buttonlink: "http://sample.com/vids/" + ??????? 
    }, 

    body = EmailGenerator.generateHtml("actionEmailTemplate", emailData); 

    Meteor.call("sendMailgunEmail", 
       "[email protected]", 
       "sample", 
       [Meteor.user().emails[0].address], 
       "Your video is live!", 
       body 
    ); 
    } 
}); 

答えて

2

それを格納することで、あなたのインサートから_idをつかむことができcollection.insertためMeteor documentationをチェックアウト:

をコレクション内のドキュメントを挿入します。固有の_idを返します。

ちょうどあなたが後で参照できる変数に、インサートの戻り値を代入:

//create a video 
Meteor.methods({ 
    createVideo: function(doc) { 
    var videoId = Videos.insert({title: doc.title, userId: this.userId, date: new Date()}); 

    var emailData = { 
     message: "Click the link below to go to your video.", 
     buttontext: "View My Video", 
     buttonlink: "http://sample.com/vids/" + videoId 
    }, 

    body = EmailGenerator.generateHtml("actionEmailTemplate", emailData); 

    Meteor.call("sendMailgunEmail", 
       "[email protected]", 
       "sample", 
       [Meteor.user().emails[0].address], 
       "Your video is live!", 
       body 
    ); 
    } 
}); 
3

collection.insert(DOC、[コールバック])

コレクション内のドキュメントを挿入します。固有の_idを返します。

だから、ローカル変数に

var videoId = Videos.insert({title: doc.title, userId: this.userId, date: new Date()}); 
関連する問題