I'd suggest if this is a one time thing that you get Node.JS installed and use code like follows if you've got a lot of pre-existing JSON-like files to load (the syntax you have is actually JavaScript). While I don't understand your data model (and changed it a tiny bit so it would compile), basically all I've done is to create one variable that contains an array of all of the "variables" that you add.
By putting them in a single array, you can then call the insert method of MongoDB to insert a large batch of documents at one time. The callback is the documents (with their _id fields set). If you have thousands of documents, you may want to use JavaScript's array slice to break the array into smaller chunks so that you don't cause a driver timeout with a really large insert.
var mongo = require('mongodb').MongoClient
, Server = require('mongodb').Server;
var allVariables = [ {
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: []
},
]
}
,
{
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: []
},
]
}
];
mongo.connect('mongodb://127.0.0.1:27017/test', function(err, db) {
if(err) throw err;
var collection = db.collection('variables');
// you may want to do them in batches rather than all at once
collection.insert(allVariables, function(err,docs){
if(err) throw err;
if(docs) {
console.log("Docs inserted: " + docs.length)
// you could do something here with the docs
}
});
});
The other option would be to actually use the json-decode (docs) functionality in PHP to load the JSON, and then insert the documents using the MongoDB PHP driver. You'll need to change the syntax of your JSON files to be pure JSON. For example, it can't have variable declarations in the file.
It might go something like this:
$bigJsonFile = file_get_contents('./variables.json', false)
$bigJsonObject = json_decode($json)
$collection->insert($bigJsonObject)