ChatGPT
ChatGPT

Reputation: 5617

how to mongoimport data to deployed meteor app?

UPDATE: this post applied to meteor.com free hosting, which has been shutdown and replaced with Galaxy, a paid Meteor hosting service

I'm using this command

C:\kanjifinder>meteor mongo --url kanjifinder.meteor.com

to get access credentials to my deployed mongo app, but I can't get mongoimport to work with the credentials. I think I just don't exactly understand which part is the username, password and client. Could you break it down for me?

result from server (I modified it to obfuscate the real values):

mongodb://client:[email protected]:27017/kanjifinder_meteor_com

my mongoimport attempt (fails authentication):

C:\mongodb\bin>mongoimport -h meteor.m0.mongolayer.com:27017 -u client -p e63aaade-xxxx-yyyy-93e4-de0c1b80416f --db meteor --collection kanji --type csv --file c:\kanjifinder\kanjifinder.csv --headerline

Upvotes: 6

Views: 2842

Answers (3)

ljack
ljack

Reputation: 53

If you get auth_failed error message your mongoimport version is too different from what's being used in meteor.com. So you need to upgrade. For ubuntu see https://docs.mongodb.org/manual/tutorial/install-mongodb-on-ubuntu/#install-the-latest-stable-version-of-mongodb

#!/bin/sh

# Script to import csvfile to meteor application deployed to free meteor.com hosting.
# Make sure your versions of mongo match with the metor.com mongo versions. 
# As Jan 2016 it seems to be 3.x something. Tested with mongoimport 3.12.

if [ $# -eq 0 ]
  then
    echo "usage: $0 xxx.meteor.com collection filename.csv"
    exit 1
fi

URL=$1
COLLECTION=$2
FILE=$3

echo Connecting to $URL, please stand by.... collection=$COLLECTION file=$FILE

PUPMS=`meteor mongo --url $URL | sed 's/mongodb:\/\// -u /' | sed 's/:/ -p /' | sed 's/@/ -h /'  | sed 's/\// -d /'`



mongoimport -v $PUPMS --type csv --headerline --collection $COLLECTION  --file $FILE

Upvotes: 0

davidd8
davidd8

Reputation: 183

Using mongodump and mongorestore also works:

  1. Dump data from existing mongodb (mongodb url: mongodb://USER:PASSWORD@DBHOST/DBNAME)

    mongodump -h DBHOST -d DBNAME -u USER -p PASSWORD
    

    This will create a "dump" directory, with all the data going to dump/DBNAME.

  2. Get the mongodb url for the deployed meteor app (i.e. www.mymeteorapp.com)

    meteor mongo --url METEOR_APP_URL
    

    Note: the PASSWORD expires every min.

  3. Upload the db dump data to the meteor app (using an example meteor db url)

    mongorestore -u client -p dcc56e04-a563-4147-eff4-5ae7c1253c9b -h production-db-b2.meteor.io:27017 -db www_mymeteorapp_com dump/DBNAME/
    

    All the data should get transferred!

Upvotes: 4

ChatGPT
ChatGPT

Reputation: 5617

OK got it. This helped: http://docs.mongodb.org/manual/reference/connection-string/

mongoimport --host meteor.m0.mongolayer.com --port 27017 --username client --password e63aaade-xxxx-yyyy-93e4-de0c1b80416f --db kanjifinder_meteor_com --collection kanji --type csv --file c:\kanjifinder\kanjifinder.csv --headerline

Upvotes: 5

Related Questions