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
Related
I'm using express with Node.js. Installed MySQL globally with this command :
npm install -g mysql
Afterwards I included this in my app.js file :
var mysql = require('mysql');
var db = mysql.createConnection({
host :'localhost',
user :'root',
password :'root',
database :'nodejs'
});
db.connect(function(err) {
if (err) throw err;
console.log("Connected!");
});
Unfortunately, I get an error :
ECONNREFUSED 127.0.0.1:3306
No clue what am I supposed to do.
The problem is you have not installed MySQL (database server).
With this command:
npm install -g mysql
That you did is install the npm package (as global) that only is a javascript "wrapper" to use in node.js for communicate with MySQL, but see that you have not installed MySQL.
To install MySQL take a look to this link
The install of MySQL Server depends on what operative system are you using and usually you use a system command, or an executable installer (in Windows), but never npm.
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
What is the difference between the npm module MongoDB and the downloaded MongoDb?
The "downloaded MongoDB" (from here) is the actual database server software (MongoDB itself). The mongodb npm module is the node.js native client driver used to access the services of a MongoDB database server from a node.js app.
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.
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.