将 meteor.userId 插入 mongoDB
insert meteor.userId into mongoDB
我想在 simpleSchema 中初始化一个字段。我想将 userId 设置为字符串字段。
架构如下:
AdsSchema = new SimpleSchema({
title: {
type: String,
label: "Title"
},
insertedBy: {
type: String,
label: "Inserted By",
autoform:{
type:"hidden"
},
autoValue: function() {
if (this.userId) {
return this.userId;
}
}
}
}
但是用autoform插入后,插入的文档是:
{
"_id" : "Zm5TML5bwJhyN8B9F",
"title" : "test"
}
表示"insertedBy"字段有"null"值!
我该如何解决这个问题?
试试 if(Meteor.userId()) return Meteor.userId()
this
in autoValue 的属性有限,请查看文档 Autoform Docs
对 autoValue 进行了一些研究,在 cleaning Data
下提到了 属性 extendAutoValueContext
这有助于使用 userId
.
我想在 simpleSchema 中初始化一个字段。我想将 userId 设置为字符串字段。
架构如下:
AdsSchema = new SimpleSchema({
title: {
type: String,
label: "Title"
},
insertedBy: {
type: String,
label: "Inserted By",
autoform:{
type:"hidden"
},
autoValue: function() {
if (this.userId) {
return this.userId;
}
}
}
}
但是用autoform插入后,插入的文档是:
{
"_id" : "Zm5TML5bwJhyN8B9F",
"title" : "test"
}
表示"insertedBy"字段有"null"值!
我该如何解决这个问题?
试试 if(Meteor.userId()) return Meteor.userId()
this
in autoValue 的属性有限,请查看文档 Autoform Docs
对 autoValue 进行了一些研究,在 cleaning Data
下提到了 属性 extendAutoValueContext
这有助于使用 userId
.