Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/mongodb/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ruby-on-rails-3/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
MongoDB回调错误_Mongodb_Meteor_Callback - Fatal编程技术网

MongoDB回调错误

MongoDB回调错误,mongodb,meteor,callback,Mongodb,Meteor,Callback,我正在使用Meteor和MongoDB开发一个应用程序,尝试使用嵌套回调访问新插入的文档,如下所示。但是,在数据库中没有匹配文档的情况下,我不断遇到一个错误,即使我成功地回调了insert语句。我不知道为什么Mongo找不到我刚才插入的文档。我知道这些方法是异步的,但我假设一旦find函数返回,回调将允许我访问新插入的文档。我试图用自己的回调将find放在insert语句之外,但得到了相同的错误 我也附上了错误信息。在此问题上的任何帮助都将不胜感激 insertEntryForm.cal

我正在使用Meteor和MongoDB开发一个应用程序,尝试使用嵌套回调访问新插入的文档,如下所示。但是,在数据库中没有匹配文档的情况下,我不断遇到一个错误,即使我成功地回调了insert语句。我不知道为什么Mongo找不到我刚才插入的文档。我知道这些方法是异步的,但我假设一旦find函数返回,回调将允许我访问新插入的文档。我试图用自己的回调将find放在insert语句之外,但得到了相同的错误

我也附上了错误信息。在此问题上的任何帮助都将不胜感激

    insertEntryForm.call(entryFormObj, (error, result) => {
                if (error) {
                    console.log(error);
                    toastr['error'](error.reason);
                }
                else {
                    toastr['success']("Entry form created!");
                    EntryForms.find({_id: result}, function(err, res) {
                        console.log(res);
                    });
                }
            }
        );

根据
提供的文档和示例,插入回调的第二个参数是插入的对象,在您的
find
中,您正在查找带有
result
的文档,它应该是
result.\u id
,因此这应该有效:

EntryForms.find({_id: result._id}, function(err, res) {

事实证明,这个问题与我在Meteor中发布/订阅我的对象的方式有关。我在router.js文件中注册了我的订阅,然后可以按预期访问我的收藏。把这件事归因于我对流星的小小体验

我已经记录了insert回调的结果,它返回插入的EntryForms对象的_id。很遗憾,尝试解决方案时产生了相同的错误。嗯。。很抱歉,这不起作用,但您说您附加了错误消息,但我看不到它,如果您附加它,也许您可以获得更多帮助。您可以发布您的
entryFormObj
请?
EntryForms.schema=new SimpleSchema({u id:{type:String,regEx:SimpleSchema.regEx.id},事件:{type:String},电子邮件:{type:String,optional:true},name:{type:String},userId:{type:String,optional:true},条目:{type:[Object],defaultValue:[]},};
export const insertEntryForm=new ValidatedMethod({name:'entryForms.insert',validate:entryForms.simpleSchema()。pick(['event',email',name',userId'))。validator)({clean:true,filter:false}),运行({event,email,name,userId}){if(!this.userId){throw new Meteor.Error(“entryForms.insert”,“未授权创建新条目表单”);}const entryForm={event,email,name,userId,};const entryFormId=entryForms.insert(entryForm);return entryFormId;}});