如何在提交mongodb和meteor上获得变量

时间:2017-03-03 20:15:31

标签: javascript html mongodb meteor meteor-autoform

所以我正在研究一个等待列表类型的应用程序。当用户将他们的信息提交到列表中时(使用autoform),他们应该通过Twilio服务发送消息。

我目前有一个使用twilio的硬编码变量

发送短信的方法

Meteor.methods({
sendSMS: function (phoneNumber) {
    var authToken = 'token value here';
    var accountSid = 'sid value here';
    twilio = Twilio(accountSid, authToken);
    twilio.sendSms({
        to: phoneNumber, // Any number Twilio can deliver to
        from: '+18.....', // A number you bought from Twilio and can use for outbound communication
        body: 'You have been added to the waitlist' // body of the SMS message
    }, function (err, responseData) { //this function is executed when a response is received from Twilio
        if (!err) { // "err" is an error received during the request, if any
            // "responseData" is a JavaScript object containing data received from Twilio.
            // A sample response from sending an SMS message is here (click "JSON" to see how the data appears in JavaScript):
            // http://www.twilio.com/docs/api/rest/sending-sms#example-1
            console.log(responseData.from); // outputs "+14506667788"
            console.log(responseData.body); // outputs "word to your mother."
        }
    });
}
});

以下是我使用硬编号的事件:

Template.home.events({
    "submit #student-form": function(event) {
        event.preventDefault();
        var phoneNumber = '+18.....';
        Meteor.call("sendSMS", phoneNumber);
        // alert("You have been added to the WaitList");
        swal("Success!", "You have been added to the WaitList", "success")
    }
});

我的快速表格

            {{>quickForm id="student-form" collection="Students" type="insert" template="bootstrap3-horizontal" label-class="col-sm-3" input-col-class="col-sm-9"}}

我想知道的是如何获取刚刚提交到mongodb集合中的电话号码值,以便我可以使用twilio向该特定电话号码发送消息?

1 个答案:

答案 0 :(得分:0)

OP在这里找到答案:Find Value in Meteor Mongo

  

如果您要从退回的文档中检索字段,   您可以使用fields选项指定:

database.findOne({}, {sort: {'timeStamp' : -1}, limit:1, fields: {'myField': 1, _id: 0})
     

那将以如下格式检索对象:

     

{'myField': 'value of myField'}