I am currently working on developing a meteor package that will allow users to import JSON files into collections in a mongoDB. However, I'm uncertain about the feasibility of this task.
The idea is for the user to upload a JSON file and specify the collection name in an input field for the import process. Subsequently, the JSON array should be stored in the specified 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);
}
});
However, I am faced with three challenges:
1) How do I handle the actual file upload process, especially since the file needs to be uploaded temporarily?
2) Is there a way to dynamically use the inputted collection name?
3) How can I ensure that the imported data is inserted correctly? Using insert might simply append the new data to existing data, correct?