Dan
Dan

Reputation: 125

Manually Edit Collections

I'm relatively new to Meteor and I was wondering how I manually edit the mongoDB for Meteor Collections.

If I declare a new collection on both the client and server:

People = new Meteor.Collection("people"); 

Then I create an array of names on the server and insert it into the collection:

var names = ["Dan", "Bob", "Sarah"];
for(var i=0; i<names.length; i++)
{
    People.insert({name: names[i]}); 
}

How do I add fields to the database and/or change fields in the database manually for development purpose? If I retype the names in the 'names' array and relaunch the app, it doesn't update the database on the server like I expected it would.

Thanks!

Upvotes: 0

Views: 251

Answers (1)

Tarang
Tarang

Reputation: 75975

Use the javascript developer console in chrome/safari or firebug in firefox

while your app is running you can edit your names.

Your changes will be done live so you can debug and play around quite alot. Something like this might work:

People.find().fetch()
=> lists all the people

Edit one

People.update("_id value from above of the person", {$set:{name:"New Name"}})

Why the method you're using isn't working:

Meteor won't add the names again to the People collection if its already populated. So just run meteor reset to clear everything in your collection. And run meteor again to use your new updated values

Upvotes: 1

Related Questions