Collection access in html file

i have given code. i want to print lat or long in script in html file.When i do that i am finding error MyCollection is not defined.can anyone tell me?

export const MyCollection = new Mongo.Collection(‘myCollection’);
MyCollection.insert(
{
“lat” : 21.1458,
“long” : 79.0882
},
{
“lat” : 25.4358,
“long” : 81.8463
},
{
“lat” : 25.3176,
“long” : 82.9739
}
)

var findCollection = MyCollection.find().fetch();
console.log(findCollection );-

That’s not valid syntax. You are passing your data objects to the insert method incorrectly. If you look at your code, you basically have this:

MyCollection.insert(object1, object2, object3);

If you look at the docs for insert, you will see that only object1 contains data to be inserted. The others are completely unexpected and you are probably getting errors in your console.

You could insert those three locations as an object, something like:

MyCollection.insert({
  location1: { lat: 21.1458, long: 79.0882 },
  location2: { lat: 25.4358, long: 81.8463 },
  location3: { lat: 25.3176, long: 82.9739 }
});

I also think you may not have understood export or how your code should be structured to do what you want, in which case it may be more helpful to outline your requirement in more detail.

Good luck :slight_smile:

Hi, i m beginner for meteor I want to insert data in collection using api not static and access that collection in .html file to make dynamic marker on google map

I recommend you start with a simple tutorial to get a better understanding. Try the “to do” app to begin with:

https://www.meteor.com/tutorials

1 Like

hi, see this is simple thing they have done …tehy are showing only data in template.they are not talking about data binding…I have seen and tried with to do app also.
Can you please suggest me to do this or any other option?