在具有特定 ID 的灯具中创建 Meteor 用户? [英] Create a Meteor User in Fixtures with specific ID?
本文介绍了在具有特定 ID 的灯具中创建 Meteor 用户?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要创建一个装置文件,并且在重置后我的 Meteor.user
需要有一个非常具体的 ID,因为我需要保留它与其他使用用户 ID 的数据的关系.
I need to create a fixtures file and after a reset my Meteor.user
needs to have a very specific ID because I need to preserve its relationships to other pieces of data, which use the user ID.
固定装置:
if ( Meteor.users.find().count() === 0 ) {
Accounts.createUser({
_id: "LHrhapueRmyJkajZ2", // This does not work, but I need it to be this.
username: 'admin',
email: 'admin@none.com',
password: '123456',
profile: {
first_name: 'John',
last_name: 'Doe',
company: 'ABC',
}
});
};
更新:
我想出了另一种方法:
if ( Meteor.users.find().count() === 0 ) {
var userId = Accounts.createUser({
username: 'admin',
email: 'none@none.com',
password: '123456',
profile: {
first_name: 'John',
last_name: 'Doe',
company: 'ABC',
}
});
};
然后在我的 fixtures
文件的其余部分中,我可以使用 userId
变量来分配我想要的任何关系".
Then in the rest of my fixtures
file I can use the userId
variable to assign any "relationships" I want.
推荐答案
你可以有一个全局变量,当分配一个没有变量的var时,这是全局的.
You can have one global variable, when assigned one var without variable, this is global.
if ( Meteor.users.find().count() === 0 ) {
userId = Accounts.createUser({
username: 'admin',
email: 'none@none.com',
password: '123456',
profile: {
first_name: 'John',
last_name: 'Doe',
company: 'ABC',
}
});
};
另一方面,你可以有一个 Session.set('user',value);
On the other hand, you can have one Session.set('user',value);
if ( Meteor.users.find().count() === 0 ) {
userId = Accounts.createUser({
username: 'admin',
email: 'none@none.com',
password: '123456',
profile: {
first_name: 'John',
last_name: 'Doe',
company: 'ABC',
}
});
Session.set('user',userId);
};
当你想获取值时:
Session.get('user');
这篇关于在具有特定 ID 的灯具中创建 Meteor 用户?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文