meteor connection to an other mongodb (not the local one) - javascript

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:
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.
how do I come back to the local mongodb of my appli
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

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:
Start meteor application in one window
In another window connect to it's local MongoDB by the running port. ( in this case on 3001 ), just to check:
mongo --port 3001
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.
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.

Related

MongoDB disabled by default [duplicate]

I have to meteor application in local (admin and client). Applications run on different port 3000 and 3003. I want to use both app should use the same DB. export MONGO_URL=mobgodb://127.0.0.1:3001/meteor will be okay. But I would like to know any argument to pass with meteor command to setup environment variable to use the same DB.
If you are looking for a start script you could do the following:
In the root of your app, create a file called start.sh:
#!/usr/bin/env bash
MONGO_URL=mobgodb://127.0.0.1:3001/meteor meteor --port 3000
Then run chmod +x start.sh
You can then start your app just by typing ./start.sh

cannot start nodejs web api hosted in Azure

Learning nodejs and started to created my own restful API using restify.
I have created a very simple server.js file which contains basically a hello world type example starting up like:
server.post('/api/messages', servicemanager.verifyFramework(), servicemanager.listen());
server.get(/.*/, restify.serveStatic({
'directory': '.',
'default': 'index.html'
}));
server.listen(process.env.port || 3978, function () {
console.log('%s listening to %s', server.name, server.url);
});
which works fine locally. I cant hit http://localhost:3978 and I can test my API calls just fine calling http://localhost:3978/api/messages.
I have deployed my code into bitbucket and now I want to host these APIs in Azure using App Services.
My project structure is like so:
/topfolder
-/myproject
-/node_modules
-/node_modules...
server.js
package.json
index.html
When I setup the new app service in Azure, I can see that the deployment receives the code from BB, but the service never responds to my requests.
I have setup the home path of the app to live in: /site/wwwroot/topfolder/myproject and I can see the index.html when I navigate to http://myproject.azurewebsites.net so thats good.
I actually get a 404 error:
The resource you are looking for has been removed, had its name changed, or is temporarily unavailable.
There are heaps of examples of how to setup continuous deployment using bitbucket and for the most part, they all seem to work, but my server.js file doesnt seem to be the getting called or starting up.
How can I debug whats going on here?
Is the packages.json file used in this scenario by Azure?
Thanks.
As the root directory path of the application hosted on Azure App Services, is D:\home\site\wwwroot. And about the nodejs application, the Azure fabric will find the entrance script in root directory like server.js. And the requests are handled via web.config in root directory. If there is missing server.js or web,config file, you will occur 404 error.
You can try to modify or your application's structure, like to:
-/node_modules
-/node_modules...
server.js
package.json
index.html
Then, you deploy your application to Azure via GIT or from BB, the Azure deployment task will run command npm install and generate the web.config wile in the root directory.
Any further concern, please feel free to let me know.

MONGO_URL for running multiple Meteor apps on one server

I have one Meteor application running on my Ubuntu server (Digital Ocean). I use Meteor Up (MUP) to deploy and keep the app running. Everything works fine.
However, when I try to deploy a second app on the same server, something goes wrong in connecting to the MongoDB. I get a long and unreadable error message that starts "Invoking deployment process: FAILED" and then ends with
Waiting for MongoDB to initialize. (5 minutes)
connected
myapp start/running, process 25053
Waiting for 15 seconds while app is booting up
Checking is app booted or not?
myapp stop/waiting
myapp start/running, process 25114
And the app refuses to run. I have tried a number of things to fix this and will edit this post if more info is requested, but I'm not sure what's relevant. Essentially I don't understand the Error message, so I need to know what the heck is going on?
EDIT:
I want to add that my app runs fine if I go into the project folder and use the "meteor" command. Everything runs as expected. It is only when I try to deploy it for long-term production mode with MUP that I get this error.
EDIT:
I moved on to trying mupx instead of mup. This time I can't even get past the installation process, I get the following error message:
[Neal] x Installing MongoDB: FAILED
-----------------------------------STDERR-----------------------------------
Error response from daemon: no such id: mongodb
Error: failed to remove containers: [mongodb]
Error response from daemon: Cannot start container c2c538d34c15103d1d07bcc60b56a54bd3d23e50ae7a8e4f9f7831df0d77dc56: failed to create endpoint mongodb on network bridge: Error starting userland proxy: listen tcp 127.0.0.1:27017: bind: address already in use
But I don't understand why! Mongod is clearly already running on port 27017 and a second application should just add a new database to that instance, correct? I don't know what I'm missing here, why MUP can't access MongoDB.
It's tricky without your mup.json to see what's going on here. Given what you said, it looks like your 2nd app deployment tries to override/boot mongodb over the 1st one which is locked, the mongodb environment fails to boot, causing then the fail. You should tackle this different ways:
If your objective is to share your mongoDB, point the MONGO_URL from your 2nd mup.jon on your first mongodb instance. It's generally something along the 2701X ports. As it's a shared DB, changes in one database could affect the other.
meteor-up oversees the deployment of your app from a meteor-nice-to-test thing to a node+mongodb environment. You can spawn another mongod instance with :
mongod --port 2701X --dbpath /your/dbpath --fork --logpath /log/path on your DO server and then point MONGO_URL there.
Last but not least, mupx having docker under the hood. Using mupx for your deployments should isolate both apps from each other.

MeteorJS : How do I check the data fetching from mongoDB on console client?

We have deploy the MeteorJS code on Ubuntu server. We haven't created any client to access this MeteorJS service. First we wanted to verify the service are running properly. Can any one suggest the steps for check the deployment is correct.
We install Meteor on Ubuntu : curl https://install.meteor.com/ | sh
MonogoDB - Already install for NodeJS application - Its Working!
Copy the Code Meteor Code to server using WinSCP
Set the MongoDB path for Code : export MONGO_URL=mongodb://ip:27017/userDB
Run Command to start the app: sudo nohup meteor --port 3001 --production &
Thanks.

Meteor MongoDB Collection Not Accessible to Meteor publish

I have imported data into a meteor mongodb database. Here is what I did:
With the meteor app running via
$ yourMeteorAppDir meteor
in one terminal and in another terminal start mongodb running via
$ mongod
Startup yet another terminal and run the following to import data into your meteor app's database with:
$ mongoimport -h localhost:3001 -d meteor -c collectionNameHere < jsonFileNameHere.json
However, after importing the documents from the json file I am finding that the collection is not being accessed by my Meteor app. Specifically, when I attempt to publish the collection with:
Meteor.publish('collectionNameHere', function()
{return collectionNameHere.find();
});
I am seeing:
Exception from sub ci9tk9AsFeyngHWwE ReferenceError: collectionNameHere is not defined
I20141203-07:15:18.436(-5)? at null._handler (app/server/collectionName.js:9:14)
I20141203-07:15:18.436(-5)? at maybeAuditArgumentChecks (packages/ddp/livedata_server.js:1599)
I20141203-07:15:18.436(-5)? at _.extend._runHandler (packages/ddp/livedata_server.js:943)
I20141203-07:15:18.437(-5)? at _.extend._startSubscription (packages/ddp/livedata_server.js:769)
I20141203-07:15:18.437(-5)? at _.extend.protocol_handlers.sub (packages/ddp/livedata_server.js:582)
I20141203-07:15:18.437(-5)? at packages/ddp/livedata_server.js:546
I can see the collection in mongo via meteor mongo and can query it via find. Do I need to create the MongoDB collection from the app instead of via an import?
Create a new database_dump.json in your projects root directory.
Then open your terminal and change directory to your projects root directory. For example cd /var/www/html/meteor/myapp/.
Type mongoimport --db meteor --collection mynewcollection --type json --headerline --file '/var/www/html/meteor/myapp/database_dump.json' -h 127.0.0.1:3001 --jsonArray
New Mongodb collection
// Lib
MyNewCollection = new Meteor.Collection('mynewcollection');
Publish your new collection.
// Server
Meteor.publish("mynewcollection", function() {
return MyNewCollection.find({});
});
Subscribe to it
// Client
Meteor.subscribe("MyNewCollection");
Have fun with Meteor

Categories