I'm currently a beginner in js and mongoDB, and currently learning meteor. I'm having issues while trying to populate a db in mongo. I have an db file, that is in .txt(i've changed the format to JSON trying to solve this), and I would like to populate mongo with it.( actually, further in the project my idea is to update/increase/merge the db, every month with another .txt file so the db will be populated every month with a new .txt file.)
The idea is to use the db, input to generate graphs, and perform several other calculations after it is properly populated.
I've tried several tutorials, and none seems to be working. So I'm either not able to show the result(HTML newbie), or I'm dumb enough to be doing something outside limits here.
the code is as follows:
Mais.js(server):
import { Meteor } from 'meteor/meteor';
Meteor.startup(() => {
Collection = new Mongo.Collection('db');
// code to run on server at startup
});
Mais.js (client);
import './main.html';
Collection = new Mongo.Collection('db');
Template.Upload_1.onCreated(
function helloOnCreated(){}
);
Template.Upload_1.helpers({
db : function() { return Collection.find();},
});
Template.Upload_1.events({
'onclick Process': function(){
var reader = new FileReader();
var jsonParser = new JSONParser();
var jsonObject = jsonParser.parse(reader);
var test0 = jsonObject.get("test0"); //just choose the first .txt entry value for testing, but will add other ones
Collection.insert(test0);
}
});
main.html
<head><title>test5</title></head>
<body>
{{> Upload_1}}
<p></p>
<p></p>
</body>
<template name="Upload_1">
<div class = "container">
<header><h1>File_READ</h1>
<input type="file" id="fileinput" />
<input type="submit" id="Process" value="Process"/>
</header></div>
<body>
<h2>Results</h2>
{{#each db}}
<p> {{> Collection}}</p>
{{/each}}
</body>
</template>
.json file(or .txt) example:
[
{ test0: "01/02/03", test1: "10", test2: "11", test3: "101" },
{ test0: "02/02/03", test1: "20", test3: "12", test3: "102" },
{ test0: "03/02/03", test1: "30", test3: "13", test3: "103" },
]
Im currently using METEOR@1.4.2.3 release.
Is there is an easier way to do this?
If there is any beginner tutorial for learning how to do this i would also appreciate it!