I have a huge javascript file that reads sort of like this:
var MyVariable1 = [ {
ThingsToGet: [
{
first_thing: "SOMETHING ONE",
second_thing: [[1, 0], [2, 0], [3, 4], [4, 4], [5, "x"], [6, "x"]]
third_thing: 0,
fourth_thing: []
},{
first_thing: "SOMETHING TWO",
second_thing: [[1, 0], [2, 5], [3, 4], [4, 4], [5, "x"], [6, "x"]],
third_thing: 0,
fourth_thing: []
},{
first_thing: "SOMETHING THREE",
second_thing: [[1, 0], [2, 0], [3, 4], [4, 4], [5, 2], [6, 2]],
third_thing: 0,
fourth_thing: []
},
]
}
];
var MyVariable2 = [ {
ThingsToGet: [ etc, etc, etc...
I'd like to shove all of that into a MongoDB database and have the client just grab the variables he/she needs via AJAX so they won't have to download the whole file. An additional reason is the data in the file is also semi-sensitive so it would also be nice if it couldn't be downloaded directly.
Just to make it a little harder, I also need to use Underscore.js to combine the 'MyVariables' like so:
var CombinedVariables = _.union(MyVariable1, MyVariable2);
I've seen this example: http://media.mongodb.org/zips.json but I don't know if in my case whether each 'MyVariable' variable should be a separate document or collection or what.
And as I'm typing this I'm starting to wonder if this is possible at all, it would have to work like this:
var CombinedVariables = _.union(MyVariable1, MyVariable2);
//both variables are stored in mongo, keep in mind there are thousands of them
for (var i = 0; i < CombinedVariables.length; ++i) { blah blah blah };
//we do some things with each variable
Somewhere in there would have to be an Ajax function to get the variables, but I'm not sure where and I'm not even sure if it's possible to do it that way.
So to sum up: I'm new to JSON, AJAX & MongoDB, I don't know how to format the JSON, I don't know how to fetch the variables and I don't know if this is possible or even worth trying.
ps I'm using PHP server-side, possibly with this Mongo REST server thing which looks interesting: https://github.com/joevallender/slim-php-mongo-rest