0
我正在構建一個應用程序,它從我從另一個域提供的幾個外部JSON提要中提取其數據。如何定期從外部JSON訂閱源更新流星收藏?
我想在服務器上構建集合,以便我可以使用$附近的位置查詢,但我需要定期檢查這些JSON訂閱源以查看它們是否已更新,如果它們有我需要相應地更新我的收藏。
有沒有這樣做的「標準」方式? (檢查我在服務器上有什麼是最新版本?)
編輯...更多信息!
我的JSON提要都有一個唯一的標識符(稱爲url_title
,但在所有提要中絕對是唯一的),如果我只想弄清楚如何格式化查詢,我可以在upsert
中使用。這是否與setInterval
結合使用?我的一個飼料是這樣的:
[{"offer_title":"NEW TEST OFFER!!!",
"url_title":"new-test-offer_144",
"offer_desc":"description here",
"offer_start":"2014-07-10",
"offer_end":"2014-07-12",
"offer_category":"food-drink",
"offer_advertiser":"Testing Corp",
"location": {
"type": "Point",
"coordinates": [-5.53596,50.12121]
}
} ...
而且我在數據拉(目前客戶端)是這樣的:
Offers = new Meteor.Collection(null);
HTTP.get("http://myappurl.com/offers.json", function(err,result) {
if (result.statusCode === 200) {
respJson = JSON.parse(result.content);
for (var i = 0; i < respJson.length; i++) {
console.log('inserting '+respJson[i]['offer_advertiser']);
Offers.insert(respJson[i]);
}
//Commented out because I need to move this server side
//Offers._ensureIndex({location: "2dsphere"});
}
else {
console.log(result.statusCode);
}
});
如果我把這個包在Meteor.setInterval,並給它一段相對較長的間隔時間,那會起作用嗎?插入/ upsert格式會是什麼樣子?
聽起來不錯;我怎麼會去呢?用某種僞(節點)cron?或者我會在應用程序本身內部做到這一點? – BellamyStudio
你可以在meteor裏面創建'cron'作業,只需在你的服務器端代碼中使用Meteor.setInterval,最好把它放在Meteor.startup()裏面。 – cwohlman