2015-04-17 129 views
0

我在server/fixtures.js文件下面的代碼:Accounts.createUser不會保存個人資料

var userId = Accounts.createUser({ 
    username: "tester", 
    email: "[email protected]", 
    password: "foobar", 
    profile: { name: "Max" } 
}); 
var user = Meteor.users.findOne({_id: userId}); 
console.log(user.profile.name); 

現在,當我運行meteor它記錄undefined。我究竟做錯了什麼?

回答

-1

我認爲你需要使用流星出版物&訂閱。查看link 瞭解更多信息。

例子:

if (Meteor.isServer){ 
    Meteor.publish('userdata', function() { 
    if(!this.userId) return null; 
    return Meteor.users.find(this.userId); 
    }); 
} 

if (Meteor.isClient){ 
    Meteor.subscribe('userdata'); 
    console.log(Meteor.user()); 
} 
0

因此,問題是console.log在服務器上不可用(根據Meteor目錄約定,此文件運行時)。如果您想登錄到服務器控制檯,則可以使用與console.log相同的Meteor._debug()。您也可以考慮將代碼包裝在Meteor.startup(function() {});區塊中,以便在服務器啓動後立即運行。

+1

console.log在服務器上可用。您可以在運行流星服務器的窗口中看到輸出。我自己回答了這個問題,我假設我在某處定義了一個Accounts.onCreateUser回調函數。 – esBeee

相關問題