I meant the browser console. I think I have found the issue, which I probably messing with the structure of the project.
I was creating the Collection in the main.js file of the client/main.js folder.
I created another main.js in the root folder of the app app/main.js and this seems to fix it. I am not sure this is safe, is there another way to make it cleaner.
If you want a local (client only) collection, then you should use Data = new Mongo.Collection('data', { connection: null }); in your client code only.
What you’ve done here is add the collection to the server as well. It’s doing that which ensures the data/insert method is created. It also means that a physical collection is being used.
Okay, I have made a local collection for now, as I don’t need to save or manipulate any data in the server. I just have this question, is this affecting the way in my client, if I need to make a list to appear and I add the data manually using Data.insert({…}); and have something like this below:
As far as your app is concerned, it’s just another MongoDB collection, except it’s not persistent, so your client will need to insert before it can find anything.
Data = new Mongo.Collection('data', { connection: null });
Meteor.startup(function (){
if(Data.find().count() === 0) {
console.log("importing data to db");
var data = json['muons']; //is an array of objects.
data = data.forEach(items => Data.insert(items));
console.log(Object(data));
};
});
As you’ve discovered, collection.find().fetch() returns an array of all objects selected by the find(). So, you just use any standard array/object processing from there. As an example, to get the phi property of array element 3: console.log(Data.find({}).fetch()[3].phi; - although you probably wouldn’t do that sort of thing in an inline statement. Something like this is more understandable:
const result = Data.find({}).fetch();
console.log(result[3].phi);
Thanks a lot, makes sense, I can manipulate it on an array-ish fashion.
I am trying to iterate the items on the html side so I can get a list with the keys and its corresponind keys like
eta: value
phi: value
etc.
So I am doing this following the turorial again, but no appear of anything.
This somehow returned the multiplication or sum of all values, so I tried the above. <li>{{eta}}, {{phi}}</li>
Wouldn’t be possible instead of hard-coding pt: to e.g., Object.keys(Data.find({}).fetch()[0])[0] or something like that in case the data will provide another key in the future , so it will add pt {{pt}} programmatically and make it more flexible rather typing each time the keys of the list.
You could certainly do that with your helper by using map() and programmatically getting the keys and their values as array elements with something like: