zoukankan      html  css  js  c++  java
  • couldn't connect to server 127.0.0.1 mongodb

    It could be combination of $PATH and Permission issue.

    Try following steps given below:

    Update your $PATH variable to point to your MongoDB bin file. In my case brew install MongoDB to this folder:

    /usr/local/Cellar/mongodb/2.4.6/
    

    In order to update your $PATH variable, do following:

    $ sudo vi /etc/paths
    

    Then, press ‘i’ to insert text in Vi and append the your MongoDB path to the end of the ‘paths’ file and restart the terminal.

    /usr/local/Cellar/mongodb/2.4.6/bin
    

    Use ‘Esc : w q’ to save and exit from Vi editor.

    Use echo to display your path variable:

    $ echo $PATH
    /usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/local/Cellar/mongodb/2.4.6/bin
    

    Now try to check the Mongo version, if you get following, then you are on the right track!

    $ mongo --version
    MongoDB shell version: 2.4.6
    

    Now we need to create the database directory. I used the default ‘/data/db’ location suggested in MongoDB docs. I also created a log directory to avoid any permission issues while Mongo tries to create any logs. Change ownership and that will do the job.

    $ sudo mkdir /data/db
    $ sudo mkdir /data/log
    $ whoami
    username
    $ chown -R username /data
    

    Now, we will create a default config file for MongoDB to be provided for the first time we run ‘mongod’ command. Now, I will also like to point out that ‘mongod’ will start a service, which will listen for incoming data connections. This is similar having ‘$service mysqld start’ executed.Let’s go ahead and create the config file. Please keep in mind that I have created very basic config file. However, you can add many other variables to configure MongoDB. This is the first time I am playing with MongoDB, so I just know as much as I read on MongoDB docs!I created ‘mongodb.conf’.

    $ sudo vi /etc/mongodb.conf
    

    Add following:

    fork = true
    port = 27017
    quiet = true
    dbpath = /data/db
    logpath = /data/log/mongod.log
    logappend = true
    journal = true
    

    Please note that the default port for MongoDB server is 27017. Use your own path for dbpath and logpath you created in Step – 5. Don’t forget to close and save the conf file.

    Now we are all set to start our MongoDB service. Open two instances of Terminal.In Terminal 1, type in:

    $ sudo mongod -f /etc/mongodb.conf
    about to fork child process, waiting until server is ready for connections.
    forked process: 3516
    all output going to: /data/log/mongod.log
    child process started successfully, parent exiting
    

    If you get above message, then know that you have successfully started your Mongod service.

    Now, to connect to it, in Terminal 2 type following:

    $mongo test
  • 相关阅读:
    JavaScript之事件冒泡和事件捕获详细介绍
    jQuer配合CSS3实现背景图片动画
    jQuery中animate()的方法以及$("body").animate({"scrollTop":top})不被Firefox支持问题的解决
    JavaScript 运用之表单验证(正则)和控制输入长度。
    input[type=submit]以及数字日期在苹果手机上显示异常的处理
    webstorm 快捷键
    Bootstrap 折叠(Collapse)插件
    input输入内容时放大问题及处理
    省市二级联动(原生JS)
    Spring4.X——搭建
  • 原文地址:https://www.cnblogs.com/qinyan20/p/4043077.html
Copyright © 2011-2022 走看看