簡體   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