Tag Archives: MongoDB

Meteor – Insert Sample Data if the MongoDB is empty

Say we have a Meteor collection called Student.

model.js

Student = new Meteor.Collection('student');

 

So i would like to have some predefined students if the collection is emtpy. So i prepare the student.json in the private folder.

private/student.json

{
  "student":
  [
    { "_id": "1", "name": "Peter" },
    { "_id": "2", "name": "Jack" },
    { "_id": "3", "name": "Mary" },
    { "_id": "4", "name": "Sam" },
    { "_id": "5", "name": "Ann" },
  ]
}

Continue reading Meteor – Insert Sample Data if the MongoDB is empty

Meteor – Connect to external MongoDB

If you start a new Meteor app, it would initialize a local MongoDB instance. If you want to use a remote one. Add the MONGO_URL environmental variable before you start the Meteor app. Ex:

MONGO_URL = "mongodb://[username]:[password]@[host]:[port]/[db]"

 

Done =)

Reference: StackOverflow – How to connect meteor to an existing backend?

Meteor – High Network IO as it keeps polling MongoDB

I was working on a Meteor project which is connected to a mongoDB hosted on MongoLab. Since it is a sandbox plan, the oplog of the mongoDB instance is not available and in that case the Meteor will keep polling the mongoDB in around every 10 seconds. This causes a very high consumption on CPU and network bandwidth.

If you are running, Meteor 0.7.0 or above and your mongoDB has oplog enabled. You won’t experienced the problem.

Since the oplog is not available so the only workaround which i could think of is to unsubscribe the dataset. Here is a main.js which is executed when the app is loaded and when the user is idle for than 3 mins. Stop the subscription and that will stop polling the mongoDB.
Continue reading Meteor – High Network IO as it keeps polling MongoDB