English 中文(简体)
如何储存专门针对Meeteor客户的数据服务器方面?
原标题:How do you store data server side that is specific to a client in Meteor?

快递安装了一台服务器机边会议标语,使你能够储存客户特有的数据。 你们在Meeteor如何做到等同?

跟踪建议采用收集方法。 如果所收集的物体的标子是会议标的,则会发挥作用。

客户和服务器共用一门课程,即通过用户的实情数据库:

if (typeof (msg.session) === "string") {
  var reconnected = (self.last_session_id === msg.session);
  self.last_session_id = msg.session;
}

服务器上的活数据Session物体:

self.id = Meteor.uuid();

但是,气象预报器确实暴露了这些物体。 如何正确获取届会信息?

如果客户会议用服务器场外会议标语对客户独一无二的用户使用Meteor#publish和Meteor#methods,那将是真正方便的。

问题回答

如果你愿意使用Meeteor的Austh分公司,这是我用一些补充意见所做的。 由于我不相信客户! 他们是谎言。

在这个例子中,我们可以说,每个用户都有一个单一魔术物体。 我们拒绝使用用户能够操纵客户方面的任何信息(即会议变量)。

在服务器上:

//Create our database
MagicalObjects = new Meteor.Collection("magicalObjects");

// Publish the magical object for the client
Meteor.publish("get-the-magical-object", function () {

//In the auth branch, server and client have access to this.userId
//And there is also a collection of users server side

var uid =  this.userId();
//I make sure that when I make this connection, I ve created a magical object 
//for each user. 

//Let s assume this adds a parameter to magical object for the userId
//it s linked to (i.e. magObject.uid = ~user id~ )

//we grab our current user from the users database, and pass to our function
checkUserHasMagicalItem(Meteor.users.findOne({_id: uid}));

var self = this;
console.log( Writing publish );
console.log( uid:   + this.userId());

var magicalObject = MagicalObjects.findOne({uid: uid});

//Now, I want to know if the magical object is changed -- and update accordingly 
//with its changes -- you might not need this part

//If you don t- then just uncomment these two lines, ignore the rest
//self.set("magicObject", uid, {magicalobject: magicalObject});
//self.flush();

//Here, we re going to watch anything that happens to our magical object
//that s tied to our user
var handle = MagicalObjects.find({uid: uid}).observe({
    added: function(doc, idx)
    {       
    //get the latest version of our object
    magicalObject = MagicalObjects.findOne({uid: uid});
    console.log( added object );
    //now we set this server side
    self.set("magicObject", uid, {magicalobject: magicalObject});
    self.flush();   
    },
     //I m not concerned about removing, but
    //we do care if it is changed
    changed: function(newDoc, idx, oldDoc)
    {
    console.log( changed object );
    magicalObject = MagicalObjects.findOne({uid: uid});
    self.set("magicObject", uid, {magicalobject: magicalObject});
    self.flush();           
    }       
//end observe

});

//for when the player disconnects
self.onStop(function() {

    console.log( Stopping );
    handle.stop();

//end onStop
});

//end publish
});

关于客户:

//this is the name of our collection client side
MagicalObject = new Meteor.Collection("magicObject");

//notice the name is equal to whatever string you use when you call
//self.set on the server

//notice, this is the name equal to whatever string you use when you
//call Meteor.publish on the server
Meteor.subscribe("get-the-magical-object");

那么,当你们想去做和 gr笑你们的魔术:

var magicObject = MagicalObject.findOne().magicalobject;

这里通知说,神灵是NOT的典型,它是我们自用的参数。 页: 1

我对长期回答表示歉意。 但是,要迅速总结:我们做了些什么?

在服务器上,我们收集了客户确实能够查阅的门槛物。 相反,我们从魔法中发表了一个单一物体——我们称之为“魔法” 根据我们确定的情况,每个物体都属于一个用户。 因此,它按照同前引书的要求成为用户特定物体。

客户创建收集(其名称为“磁性目标”),然后在服务器数据库的实际数据发生变化时发送数据。 这种收集只设计一个物体,但该物体可具有许多参数(例如:魔法、kazoo或魔法、isHarryPotter),或可以储存许多不同的物体(例如非MagicItem)。

我认为,这样做的“金属”办法是:

在服务器方面创建并公布客户收集信息

UserSession = new Meteor.Collection("user_sessions");

Meteor.publish( user_sessions , function (user) {

    return UserSession.find(user);    
});

客户

Session.set( user_id , 42);

UserSession = new Meteor.Collection("user_sessions");
Meteor.subscribe( user_sessions , Session.get( user_id ));

现在,你有一个专门针对该用户的应用软件级用户目标,你可以提出/设计。

此外,你还可以使用Meteor#methods操纵服务器上的用户收集。

值得注意的是,用户信息库不为用户工作,而用户没有在客户中登记。 我面临这一设想,因为我想要建立一个新的用户数据标,在保留至蒙巴非银行之前加以修改。 修改之处是添加从目前网页(使用铁道线客户的侧路)的URL公路上获得的属地。 但我正收到这一错误,

“在用户没有锁定的情况下,你不能使用用户使用方法”。

因此,如果你的使用案例仅限于在用户和服务器之间分享数据,用户信息包似乎就是这样做的。

某届会议的举行与收集工作没有什么不同。 如果你真心想以会议为基础的解决办法,则使用会议办法确定你们的价值观,并在需要时收回这些价值观。





相关问题
why the session in iis automatically log out?

I used iis6, and when i called a function Directory.delete(), the all the session relate this website will be logged out. and i debugged the website, i found no exception. any one have ideas on this ? ...

Check session from a view in CodeIgniter

What is the best way to check session from a view in CodeIgniter, it shows no way in their user guide, otherwise I will have to make two views on everything, which is kinda weird...still a newbie to ...

Can I get the size of a Session object in bytes in c#?

Is it possible to get the size(in bytes) of a Session object after storing something such as a datatable inside it? I want to get the size of a particular Session object, such as Session["table1"], ...

提供严格分类的出席会议物体

提供严格分类的与会机会的最佳方式是什么? 我正计划转而选择矩阵,这正在促使汇编者抱怨我的幻觉方案拟订方法......

PHP Session is not destroying after user logout

I m trying to create an authentication mechanism for my PHP Application and I m having difficulty destroying the session. I ve tried unsetting the authentication token which was previously set within ...

热门标签