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/8/meteor/3.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 在meteor中的方法更新中获取autoform中记录的_id_Mongodb_Meteor_Meteor Autoform - Fatal编程技术网

Mongodb 在meteor中的方法更新中获取autoform中记录的_id

Mongodb 在meteor中的方法更新中获取autoform中记录的_id,mongodb,meteor,meteor-autoform,Mongodb,Meteor,Meteor Autoform,我正在使用for meteor,但是当我尝试更新集合中的文档时,似乎无法获取记录的\u id来更新它 我正在使用autoform和type=methodupdate,以便在服务器端验证它。当我尝试下面的代码时,它失败了,因为\u id未定义 模板: {{#autoForm collection="Lessons" doc=lesson id="updateLessonForm" type="method-update" meteormethod="updateLesson"}}

我正在使用for meteor,但是当我尝试更新集合中的文档时,似乎无法获取记录的
\u id
来更新它

我正在使用autoform和
type=methodupdate
,以便在服务器端验证它。当我尝试下面的代码时,它失败了,因为
\u id
未定义

模板:

{{#autoForm collection="Lessons" doc=lesson id="updateLessonForm"  type="method-update" meteormethod="updateLesson"}}
        <fieldset>
            {{> afFieldInput name="categoryId" firstOption="(Select a Category)" options=categoryOptions}}
            {{> afQuickField name='title'}}
            {{> afQuickField name='summary' rows=2}}
            {{> afQuickField name='detail' rows=1}}
            {{> afQuickField name='extras' rows=1}}
            {{> afQuickField name='active'}}
        </fieldset>
        <button type="submit" class="btn btn-primary btn-block">Update Lesson</button>
    {{/autoForm}}
更新:

doc._id returns undefined

doc returns:
I20150409-23:15:22.671(-5)? { '$set': 
I20150409-23:15:22.672(-5)?    { categoryId: 1,
I20150409-23:15:22.672(-5)?      title: 'Lesson 1 update',
I20150409-23:15:22.672(-5)?      summary: 'Summary for lesson 2',
I20150409-23:15:22.672(-5)?      detail: '<p>dsffdsfd</p>',
I20150409-23:15:22.672(-5)?      extras: '<p>fdsf</p>',
I20150409-23:15:22.672(-5)?      active: false } }

doc.\u id返回未定义的
单据退回:
I20150409-23:15:22.671(-5)?{'$set':
I20150409-23:15:22.672(-5)?{类别ID:1,
I20150409-23:15:22.672(-5)?标题:“第1课更新”,
I20150409-23:15:22.672(-5)?小结:“第二课小结”,
I20150409-23:15:22.672(-5)?细节:“dsffdsfd

”, I20150409-23:15:22.672(-5)?附加条款:“fdsf

”, I20150409-23:15:22.672(-5)?活动:假}
如果您打印文档,您应该获得文档,因此
此。\u id
应更改为
文档。\u id

注意:在执行更新之前,请尝试使用
控制台.log
查看您获得的值

console.log(this._id)//should return undefined.
console.log(doc._id)//should return the id
console.log(doc)//should return the doc.
更新

为了获得
\u id
,您应该调用第二个参数

updateLesson: function (doc,doc_id) {
    check(doc, Lessons.simpleSchema());
    Lessons.update({_id: this._id}, doc);
}

单据id返回未定义20150409-23:15:22.671(-5)?{'$set':I20150409-23:15:22.672(-5)?{categoryId:1,I20150409-23:15:22.672(-5)?标题:“第1课更新”,I20150409-23:15:22.672(-5)?摘要:“第2课摘要”,I20150409-23:15.672(-5)?详细信息:“dsffdsfd p>”,I20150409-23:15:22.672(-5)?附加内容:“fdp>”,I201504009-23:23:672(-5)和
console.log(doc)
返回什么?而且我完全忘了你应该像这样更新
Lessons.update({u id:doc.{u id},{$set:{field:doc.newValue})你用钩子试过了吗?还有
onSuccess
callback?我编辑了这个问题以显示文档中的日志。我正在使用方法更新,我认为在使用方法类型时不需要执行回调挂钩。也许我的理解是错误的。方法update表示它传递两个参数,一个是documentId。我无法理解documentId在服务器端方法中是如何被访问的。明白了,它说这个方法应该有两个参数,所以这个方法应该是这样的
updatelsson:function(doc,doc\u id){console.log(doc)console.log(doc.\u id)check(doc,Lessons.simpleSchema());Lessons.update({\u id:this.\u id},doc);}
在方法上使用两个参数,
doc,docID
updateLesson: function (doc,doc_id) {
    check(doc, Lessons.simpleSchema());
    Lessons.update({_id: this._id}, doc);
}