![](/img/trans.png)
[英]How to import data from CSV file into Meteor collection at server side
[英]How to monitor changes to a collection from the server with Meteor?
每次將新文檔添加到給定集合時,我都希望發送電子郵件。 是從服務器端訂閱一個集合正確的方式與Meteor這樣做?
發布/訂閱提供了一種將觀察者附加到訂閱的方法 ,但這似乎只監視來自客戶端的連接,而不是集合本身(當客戶端連接到整個集合內容時,將調用“add”)。
執行此操作的正確方法是使用Meteor.methods()添加服務器方法。 該文檔的文檔如下: http : //docs.meteor.com/#meteor_methods 。
要發送電子郵件,您需要向另一台服務器發出請求,因為meteor尚未發送內置電子郵件。 發出http請求的文檔在這里: http : //docs.meteor.com/#meteor_http_post 。
小例子:
Meteor.methods(
create_document: function (options) {
//insert the document
//send a post request to another server to send the email
}
)
然后在客戶端上,您將調用:
Meteor.call("create_document", <your options>);
我不這么認為。 但是有一種使用YourCollection.deny()
的好方法:
在服務器上:
Meteor.startup(function(){
YourCollection.deny({
insert: function (userId, item) {
// Send your Email here, preferential
// in a asynchronous way to not slow down the insert
return false;
}
});
});
如果客戶端將項目插入YourCollection,則服務器首先運行所有拒絕函數來檢查是否允許他,直到一個返回true,否則所有允許規則除非其中一個返回true。
如果至少一個允許回調允許寫入,並且沒有拒絕回調拒絕寫入,則允許寫入繼續。 - 流星文件
請注意,您不能將YourCollection.allow()用於您想要的內容,因為它不一定會運行(如果沒有拒絕,則允許就足夠了)。
但請注意:如果您使用默認情況下使用的不安全軟件包,除非您設置自己的規則,否則將允許一切。 正如您剛才所做的那樣,您可能希望現在通過添加來允許插入
YourCollection.allow({
insert: function (userId, item) {return true;},
update: function (userId, item) {return true;},
remove: function (userId, item) {return true;}
});
在deny函數旁邊。
- 最好,簡
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.