I'm trying to create a meteor-package to import JSON-files to collections in a mongoDB. But I'm not quite sure, if this is possible.
So I want the user to upload a JSON-file. In a input-field the user also types the collection-name which has to be used for the import. After this the JSON-array should be saved to the given collection.
HTML:
<template name="importJSON">
<form id="importJson">
<input type="text" id="collection">
<input type="file" id="file">
</form>
</template>
meteor:
Template.importJSON.events({
'submit #importJson': function(e){
e.preventDefault();
var collection = e.target.collection.value;
var obj = JSON.parse(response);
db.collection.insert(obj);
}
});
So I have three problems with that:
1) How do I have to do the upload itself, as the file should be uploaded temporarily
2) How can I use the collection name given in the input-field?
3) How do I import the data in a correct way? Insert would just append the new data to the existing data, wouldn't it?