Closed ericlbarnes closed 11 years ago
Hi, I think the problem is you are trying to serialize both the query object and the options object. If you serialize them separately it will work, or you could put them into an array.
JSON.stringify({$and: {tags: { $all: ["!1"] } }});
//returns "{"$and":{"tags":{"$all":["!1"]}}}"
JSON.stringify({sortBy: "last_reply_at", order: "desc", status:"waiting"});
// returns "{"sortBy":"last_reply_at","order":"desc","status":"waiting"}"
//A few example functions
saveQuery = function(query, options) {
JSON.stringify([query, options]);
};
runSavedQuery = function(queryStirng) {
var queryArray = JSON.parse(queryString);
MyCollection.query(queryArray[0], queryArray[1]);
};
@davidgtonge You rock! Thanks for that reply.
Maybe I am missing something obvious but I am trying to store the actual query part in a db as a saved search and then use it to filter the collection.
Following your example:
If I take the main part out:
That isn't valid json. Do you have any better ideas on how to store this in a db to be used later?
I was trying to store something like the following and merge the two parts together but isn't very clean and never could get it to work well:
Here is an actual query that works directly just not parsing via parseJSON