我有这个功能:
Meteor.setInterval( function () {
productDate = Products.findOne({isItReady: false});
console.log(productDate+ 'found something')
var timeNow = Date();
var timeNow = timeNow.toString();
var timeCreated = productDate.createdAt
var timeCreated = timeCreated.toString();
var productId = productDate._id;
productDate = Products.findOne({});
if (timeCreated <= timeNow) {
console.log("check")
Products.update({_id: productId}, {$set: {isItReady: true}})
}
}, 5000);
所有console.log都是成功的,但我的收藏并没有更新isItReady的新值。可能是什么问题?
更新
我的功能现在是:
Meteor.setInterval( function () {
productDate = Products.findOne({});
var timeNow = Date();
var timeNow = timeNow.toString();
var timeCreated = productDate.createdAt;
var timeCreated = timeCreated.toString();
var productId = productDate._id;
if (timeCreated <= timeNow) {
console.log("check")
Products.update({_id: productId}, {$set: {isItReady: true}}, function(error, result) {
console.log(productId)
if (error){
console.log(error.reason) //check the error
} else{
console.log("File with the id: " + result + " just get update")
}
});
}
}, 5000);
产品系列的定义:
Products = new Mongo.Collection("products");
我从服务器控制台获取:
I20150426-19:12:59.818(3)? check
I20150426-19:12:59.820(3)? eXPzq5K6Kam35X27m
I20150426-19:12:59.821(3)? File with the id: 1 just get update
但实际上,当我在此更新后检查我的收藏时,它是这样的:
meteor:PRIMARY> db.products.find().pretty()
{
"_id" : "eXPzq5K6Kam35X27m",
"tooteNimetus" : "2001311",
"partii" : "23",
"trummel" : "1",
"tootmistellimus" : 1,
"startOfCountdown" : ISODate("2015-04-26T16:11:19.702Z"),
"createdAt" : ISODate("2015-04-26T16:10:19.702Z"),
"isItReady" : false,
"whoCreated" : null
}
虽然功能执行成功但是ItIReady没有更新到:true
答案 0 :(得分:1)
如果您看到所有控制台,还有console.log("check")
。
确保这一点。
您是否安装了不安全的软件包?运行meteor list
并检查列表中是否包含insecure
和autopublish
包。
如果列表中不,请确保您在/server
或if(Meteor.isServer)
Products.allow({
update:function(){return true;}
})
现在执行以下操作,使用callback
,就像这样。
Products.update({_id: productId}, {$set: {isItReady: true}},function(error,result){
if(error){
console.log(error.reason) //check the error.
}else{
console.log("File with the id: " + result + " just get updated")
}
})