在回调中调用Insert时没有被调用,为什么会这样?
Insert not being called when called within a callback, why is this?
当我在s3之后移动插入时,此代码有效。但是当我在回调中拥有它时,它似乎可以工作,但没有添加到数据库中,也没有在网页上更新。
Meteor.methods({
createPost: function(options){
// check(options,{
var id = Random.id();
var data = { Key: id, Body: 'Hello!'};
if(Meteor.isServer){
s3.putObject(data, function(err, data) {
if (err) {
console.log("Error uploading data: ", err);
} else {
console.log("Successfully uploaded data to s3.");
if(options.title.length > 200){
throw new Meteor.Error(413,"Title too long");
}
//if(!this.userId){
//throw new Meteor.Error(403, "You must be logged in");
//}
console.log("test")
var id = options._id || Random.id();
console.log(Posts.findOne());
Posts.insert({
_id: id,
owner: "test",
lat: options.lat,
lon: options.lon,
title: options.title,
public: !!options.public,
upvotes: 1,
downvotes: 0,
rank: 0
});
}
});
}
// });
}
});
我需要绑定到我的环境,因为它必须在一个纤维中执行。
Meteor.methods({
createPost: function(options){
// check(options,{
var id = Random.id();
var data = { Key: id, Body: 'Hello!'};
if(Meteor.isServer){
s3.putObject(data, Meteor.bindEnvironment(function(err, data) {
if (err) {
console.log("Error uploading data: ", err);
} else {
console.log("Successfully uploaded data to s3.");
if(options.title.length > 200){
throw new Meteor.Error(413,"Title too long");
}
//if(!this.userId){
//throw new Meteor.Error(403, "You must be logged in");
//}
console.log("test")
var id = options._id || Random.id();
console.log(Posts);
var ret = Posts.insert({
_id: id,
owner: "test",
lat: options.lat,
lon: options.lon,
title: options.title,
public: !!options.public,
upvotes: 1,
downvotes: 0,
rank: 0
}, function(error, results){
console.log(error)
});
console.log("test2");
}
},function () { console.log('Failed to bind environment'); }));
}
// });
}
});
相关文章:
- 函数在promise被解析后被调用,但Jasmine未通过测试.为什么?
- 在React中,为什么我必须绑定onClick函数而不是调用它
- 为什么ng控制器不调用或工作或功能不工作
- 为什么这个函数调用会破坏程序并导致未定义的变量
- 为什么使用AWS Signature v4对S3的REST调用并没有真正使用签名过程
- 为什么我的函数没有被调用呢
- 为什么我的ajax在提交用@HtmlRenderPartial加载的表单时只调用fire一次
- 为什么 JS 不在滚动时调用函数
- 为什么谷歌地图API's方法未从RequireJS中正确调用
- 为什么Jquery$.ajax在函数调用中触发所有statusCode,即使调用成功
- 为什么在调用父构造函数时在[]中发送数据
- 为什么AJAX调用有时会重定向页面
- 为什么(如何)'这'从函数内部调用回调时发生更改
- 为什么从数组调用时收到非法调用
- 对于Ajax调用,为什么innerHTML没有显示在IE中
- 为什么可以't我用Set对象调用Array.prototype.map
- HTML5 视频的 canplay/canplaythrough 事件不会在 Firefox 上调用.为什么
- chrome.tabs.sendMessage回调函数未被调用.为什么?
- 对函数的调用为什么只在第一次返回字符串,之后就没有定义?
- javascript函数作为参数-非法调用.为什么?