gpt4 book ai didi

Meteor collection.insert 回调问题

转载 作者:行者123 更新时间:2023-12-04 06:23:43 24 4
gpt4 key购买 nike

根据 meteor 文档....

collection.insert(doc, [callback])

callback Function

Optional. If present, called with an error object as the first argument and the _id as the second.


……后来下来……

On the server, if you don't provide a callback, then insert blocks until the database acknowledges the write, or throws an exception if something went wrong. If you do provide a callback, insert returns immediately. Once the insert completes (or fails), the callback is called with error and result arguments, same as for methods.


哪个是错误和 _id 或错误和结果?我确实有 Meteor.methods 正确触发他们的回调,但有错误,结果可用于范围。
我只是无法让回调在 collection.insert(doc, [callback]) 上正常工作
无论哪种方式,我都无法让我的回调注册任何东西?
function insertPost(args) {
this.unblock;
if(args) {
post_text = args.text.slice(0,140);
var ts = Date.now();
Posts.insert({
post: post_text,
created: ts
}, function(error, _id){
// or try function(error, result) and still get nothing
// console.log('result: ' + result);
console.log('error: ' + error);
console.log('_id: ' + _id); //this._id doesn't work either
});

}
return;
}
我究竟做错了什么?我从凌晨 2 点开始编码......下午 6 点我的时区......我很模糊,所以我可能(可能)遗漏了一些很明显的东西。
干杯
史蒂夫

最佳答案

这是一个错误,已在下一个版本中修复。现在,如果您提供对 insert 的回调,它将被调用 errorresult参数,其中 result是新文档的 ID,如果有错误,则为 null。

关于Meteor collection.insert 回调问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10507216/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com