我正在尝试使用meteor-collection2来验证我的集合。
我有一个服务,在服务器端:
Meteor.methods
UserSignUpService: (options) ->
# create user
Accounts.createUser options我在客户端调用的代码:
Meteor.call 'UserSignUpService',
email: 'my.email@domain.com'
password: 'mypassword'
profile:
name: 'me'这是我的方案:
# user profile
UserProfile = new SimpleSchema
name:
type: String
min: 1
max: 50
optional: false
# user
User = new SimpleSchema
emails:
type: [Object]
optional: false
"emails.$.address":
type: String
regEx: SimpleSchema.RegEx.Email
"emails.$.verified"
type: Boolean
createdAt:
type: Date
profile:
type: UserProfile
optional: false
services:
type: Object
optional: true
blackbox: true
# links to user collection
Meteor.users.attachSchema User但是,当创建用户时,我的mongo集合中并没有所有的字段:
{ "_id" : "ikvBq95JBLXMCSnhT", "emails" : [ { "address" : "my.email@domain.com" } ] }然而,它应该是:
{ "_id" : "WNkjGFhNkLpRR2Jex", "createdAt" : ISODate("2015-08-06T09:00:59.887Z"), "services" : { "password" : { "bcrypt" : "$2a$10$QvMLuI.Pv0bzzii3ZZP...fHfUlU9KiYfcsC2VHBf6q1OSPM6cfTW" }, "resume" : { "loginTokens" : [ { "when" : ISODate("2015-08-06T09:01:00.002Z"), "hashedToken" : "9KyqjRVSWm0nfIlS0sqODRmddlJ5GaG3mJ4+RMItOhk=" } ] } }, "emails" : [ { "address" : "my.email@domain.com", "verified" : false } ], "profile" : { "name" : "me" } }对这个问题有什么想法吗?
非常感谢!
发布于 2015-08-07 00:48:49
您实际上并没有设置createdAt字段的值,请尝试:
createdAt:
type: Date
autoValue: function(){
if this.isInsert return new Date()
else if this.isUpsert return { $setOnInsert: new Date };
else if this.isSet this.unset();
}您也可以在模式中省略optional: false,因为这是缺省设置。
此外,我怀疑这是更大的问题,默认情况下并不是所有的用户密钥都会返回给客户端,只有配置文件才会正常发布。例如,您期望的是服务密钥,但这通常不会出现。查看mongo控制台中的文档并查看其中的内容。您可能需要向客户端发布一组更全面的密钥。
https://stackoverflow.com/questions/31854017
复制相似问题