繁体   English   中英

Meteor 获取模式集合中的用户数据2,并自动生成

[英]Meteor get Users datas in a schema collection2, and autoform

我想在带有 collection2 和 autoform 的新集合中插入一些用户数据。 我的用户集合中有很多数据。

我不知道如何做到最好?

也许我需要发布和订阅用户集合,然后在我的架构中获取这些数据。

这是我的架构

 Posts = new Mongo.Collection('posts'); PostsIndex = new EasySearch.Index({ collection: Posts, fields: ['title','tags.tags'], engine: new EasySearch.Minimongo() // name: 'PostsIndex', // permission: function(options) { // return userHasAccess(options.userId); // always return true or false here // } }); Posts.allow({ insert: function(userId, doc) { return !!userId; } }); Schema = {}; Schema.Tags = new SimpleSchema({ tags: { type: String } }); Schema.PostsSchema = new SimpleSchema({ title: { type: String, label: '', max: 250, min: 3 }, tags: { type: [Schema.Tags] }, authorId: { type: String, label: 'Author', autoValue: function(){ return this.userId }, autoform: { type: 'hidden' } }, authorName: { type: String, label: 'AuthorName', autoValue: function(){ return this.userId.username }, autoform: { type: 'hidden' } }, createdAt: { type: Date, label: 'CreatedAt', autoValue: function(){ return new Date() }, autoform: { type: 'hidden' } } }); Posts.attachSchema(Schema.PostsSchema);

先感谢您 :)

this.userId只返回当前用户的 id 而不是对象。 this.userId.username不能工作。 使用this.userId在 Meteor.users 集合中查找用户并返回用户名属性。

var tempUser = Meteor.users.findOne({_id: this.userId});
return tempUser.username;

从流星文档

默认情况下,当前用户的用户名、电子邮件和个人资料会发布到客户端。

默认情况下,meteor 发布用户集合中文档的用户名、ID 和电子邮件字段,以便帐户系统正常工作。 如果您想要当前登录用户的用户名,您可以使用:

Meteor.user().username;

我只是在客户端助手中而不是在 autoValue 中测试了这个,但我认为这也应该在服务器上工作。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM