0

I have launched a localhost:207017 mongod 3.0.5 which is a completely separate mongodb than meteor's I want to connect to it from meteor (which has a local mongodb). I have seen in How do I use an existing MongoDB in a Meteor project? that we can use: export MONGO_URL=mongodb://localhost:27017/your_db to link "something" to my mongo server.

Question:

  1. where is this mongo_url env variable stored ie locally in my meteor appli ? Is it specifically for the meteor appli I am dealing with or for all meteor.
  2. how do I come back to the local mongodb of my appli
  3. with the following code, no collection is created in your_db BUT I have a new collection (empty) called meteor_accounts_loginServiceConfiguration.

In meteor, I am using todo example from meteor doc site

.js file

Tasks = new Mongo.Collection("tasks");

if (Meteor.isClient) {
  // This code only runs on the client
  Template.body.helpers({
    tasks: function () {
      return Tasks.find({});
    }
  });
}

.html file

<body>
  <div class="container">
    <header>
      <h1>Todo List</h1>
    </header>

    <ul>
      {{#each tasks}}
        {{> task}}
      {{/each}}
    </ul>
  </div>
</body>
<template name="task">
  <li>{{text}}</li>
</template>

Anybody has a clew how all this is setup and working and how to fix it?

Best,

G

Community
  • 1
  • 1
gdem
  • 15
  • 4

1 Answers1

0

Environment variables can be set on the command line as you launch the application, so you do not need to set this in your overall shell environment. Doing that would mean either it is global for that shell or global for all shell sessions depending if you set that permanently.

But a simple migration for me is just a few steps:

  1. Start meteor application in one window

  2. In another window connect to it's local MongoDB by the running port. ( in this case on 3001 ), just to check:

    mongo --port 3001
    
  3. After reporting connected and exiting the shell, then I run a mongoexport and mongoimport to copy the desired collection:

    mongoexport --port 3001 -d meteor -c cards | mongoimport -d meteor -c cards
    

    I am just piping the output from the export to the import which is simple. Also I am choosing to keep the same database name, but you can change if you want. Repeat exports for each collection you want.

  4. Stop the meteor application which stops the local server, and then resart with the environment setting issued before the meteor command. Again, I put everyhting in the "meteor" database, so that is what I am connecting to:

    MONGO_URL="mongodb://localhost:27017/meteor" meteor
    

When the app is started up, it hapilly reads the data from the migrated collection and displays perfectly.

For the paranoid, if you did not notice the output in the meteor startup which did not report a local MongoDB starting, then you can check the running processes and see that only your "global" MongoDB is the only instance running.

Or of course if you pointed to another machine, then there is no MongoDB running on the application server.

Blakes Seven
  • 49,422
  • 14
  • 129
  • 135