Reputation: 516
In my application, I'm building a query object some thing like below
Object {pointType: /analog/i, _id: Object}
I tried to store it in session variable,
Session.set("currentPointsQueryObject",queryObj);
Then on click event I'm getting this object
var res= Session.get("currentPointsQueryObject");
console.log(res);
but here I'm getting like below
Object {pointType: Object, _id: Object}
Meanwhile, I sent group_id to the server by geting it from session variable like
var group_id=Session.get("currentGroupId");
which is working fine(it is displaying id in server log)
Then, I've tried storing it in global variable, which returning as expected
like below on click event
Object {pointType: /analog/i, _id: Object}
but when I sent it to server side method (Immediate line after console.log() )
Meteor.call("updateGroupPoints",res,function(err,data){
console.log("updated points");
console.log(data);
});
when I log res
in server console, it is showing
{ pointType: {}, _id: { '$nin': [] } }
Althoug I have something in pointType
, It is not passed to the server.
Anyone had idea, Is this the thing related storing?
Upvotes: 2
Views: 498
Reputation: 3592
Simply stringify your RegExp via .toString()
, send it to the server and then parse it back to RegExp.
Upvotes: 0
Reputation: 2458
There's a handy way to teach EJSON how to serialize/parse Regular Expressions (RegExp) as of 2015 documented in this SO question:
How to extend EJSON to serialize RegEx for Meteor Client-Server interactions?
Basically, we can extend the RegExp object class and use EJSON.addType
to teach the serialization to both client and server. Hope this helps someone out there in the Universe. :)
Upvotes: 0
Reputation: 5273
You cannot directly serialize RegExp to EJSON, but you can:
var regexp = /^[0-9]+$/;
var serialized = regexp.source;
Send serialized
and then deserialize:
new RegExp(serialized)
Take a look at : Meteor: Save RegExp Object to Session
Upvotes: 3