Search code examples
mongodbmongoimport

mongoimport without installing the database


Is there an easy solution to install the mongoimport tool but not install all the mongo packages?

The mongoimport tool would be used on machine A but the data would be saved to machine B.

Currently, I have two machines. They both have mongo installed. However, machine A uses mongoimport and the connection points to machine B. I'd like to be able to use machine A without needing to install all other packages that comes along with the mongo installation.


Solution

  • Ubuntu

    On Ubuntu, follow the documentation for installing MongoDB CE on Ubuntu

    1. Add the package signing key

      sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 0C49F3730359A14518585931BC711F9BA15703C6
      
    2. Add a source file to the apt configuration

      • Ubuntu 12.04

        echo "deb [ arch=amd64 ] http://repo.mongodb.org/apt/ubuntu precise/mongodb-org/3.4 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.4.list
        
      • Ubuntu 14.04

        echo "deb [ arch=amd64 ] http://repo.mongodb.org/apt/ubuntu trusty/mongodb-org/3.4 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.4.list
        
      • Ubuntu 16.04

        echo "deb [ arch=amd64,arm64 ] http://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/3.4 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.4.list
        
    3. Reload local package database

      sudo apt-get update
      
    4. Install the mongoldb-org-tools package, which contains mongoimport

      sudo apt-get install -y mongodb-org-tools
      

    MacOS

    Install macports, if you have not yet. Then, do

    sudo port selfupdate && sudo port install mongo-tools
    

    Notes

    Personally, I think it is a Very Bad Idea™ to remotely import data. Your connection may easily become the bottleneck and depending on the number of documents you are going to import this may be severely limiting the performance. Furthermore, a remote connection is more likely to break by orders of magnitude, which would leave you with a partially imported file.

    I'd rather use GNU screen on the remote machine, start the import, suspend the terminal and wait for the import to complete:

    $ screen
    Screen version 4.00.03 (FAU) 23-Oct-06
    
    Copyright (c) 1993-2002 Juergen Weigert, Michael Schroeder
    Copyright (c) 1987 Oliver Laumann
    
    This program is free software; you can redistribute it and/or modify it under
    the terms of the GNU General Public License as published by the Free Software
    Foundation; either version 2, or (at your option) any later version.
    
    This program is distributed in the hope that it will be useful, but WITHOUT
    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
    FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
    
    You should have received a copy of the GNU General Public License along with
    this program (see the file COPYING); if not, write to the Free Software
    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
    
    Send bugreports, fixes, enhancements, t-shirts, money, beer & pizza to
    screen@uni-erlangen.de
    
    
                        [Press Space or Return to end.]
    $ mongoimport <your opts here>
    <ctrl+a,ctrl+d>
    $ screen -r # to reattach the detached terminal session
    

    This way, you can safely terminate your terminal session when the import is detached.