Error: couldn't connect to server 127.0.0.1: 27017 src/Mongo/Shell/Mongo. JS: 91

Source: Internet
Author: User
Tags mongodb 32 bit

Recently, I started to learn how to install Mongo in windows. It is not difficult to perform this operation. I still use it in Linux. But refer to some documents after installation. The title error was found when Mongo was started.

Finally, this problem is solved by setting the path again.

Solution: Enter the following command

[root @ localhost mongodb] # ./bin/mongod -dbpath = / data / db
Then the interface will appear:

[root @ localhost mongodb] # ./bin/mongod -dbpath = / data / db
Tue Dec 11 14:45:53
Tue Dec 11 14:45:53 warning: 32-bit servers don't have journaling enabled by default. Please use --journal if you want durability.
Tue Dec 11 14:45:53
Tue Dec 11 14:45:53 [initandlisten] MongoDB starting: pid = 3813 port = 27017 dbpath = / data / db 32-bit host = localhost.localdomain
Tue Dec 11 14:45:53 [initandlisten]
Tue Dec 11 14:45:53 [initandlisten] ** NOTE: when using MongoDB 32 bit, you are limited to about 2 gigabytes of data
Tue Dec 11 14:45:53 [initandlisten] ** see http://blog.mongodb.org/post/137788967/32-bit-limitations
Tue Dec 11 14:45:53 [initandlisten] ** with --journal, the limit is lower
Tue Dec 11 14:45:53 [initandlisten]
Tue Dec 11 14:45:53 [initandlisten] db version v2.2.2, pdfile version 4.5
Tue Dec 11 14:45:53 [initandlisten] git version: d1b43b61a5308c4ad0679d34b262c5af9d664267
Tue Dec 11 14:45:53 [initandlisten] build info: Linux domU-12-31-39-01-70-B4 2.6.21.7-2.fc8xen # 1 SMP Fri Feb 15 12:39:36 EST 2008 i686 BOOST_LIB_VERSION = 1_49
Tue Dec 11 14:45:53 [initandlisten] options: {dbpath: "/ data / db"}
Tue Dec 11 14:45:53 [initandlisten] exception in initAndListen: 10296
************************************************** *******************
 ERROR: dbpath (/ data / db) does not exist.
 Create this directory or give existing directory in --dbpath.
 See http://dochub.mongodb.org/core/startingandstoppingmongo
************************************************** *******************
, terminating
Tue Dec 11 14:45:53 dbexit:
Tue Dec 11 14:45:53 [initandlisten] shutdown: going to close listening sockets ...
Tue Dec 11 14:45:53 [initandlisten] shutdown: going to flush diaglog ...
Tue Dec 11 14:45:53 [initandlisten] shutdown: going to close sockets ...
Tue Dec 11 14:45:53 [initandlisten] shutdown: waiting for fs preallocator ...
Tue Dec 11 14:45:53 [initandlisten] shutdown: closing all files ...
Tue Dec 11 14:45:53 [initandlisten] closeAllFiles () finished
Tue Dec 11 14:45:53 dbexit: really exiting now
[root @ localhost mongodb] # ./bin/mongod -dbpath = / usr / local / mongodb / data / db /
Tue Dec 11 14:46:53
Tue Dec 11 14:46:53 warning: 32-bit servers don't have journaling enabled by default. Please use --journal if you want durability.
Tue Dec 11 14:46:53
Tue Dec 11 14:46:53 [initandlisten] MongoDB starting: pid = 3819 port = 27017 dbpath = / usr / local / mongodb / data / db / 32-bit host = localhost.localdomain
Tue Dec 11 14:46:53 [initandlisten]
Tue Dec 11 14:46:53 [initandlisten] ** NOTE: when using MongoDB 32 bit, you are limited to about 2 gigabytes of data
Tue Dec 11 14:46:53 [initandlisten] ** see http://blog.mongodb.org/post/137788967/32-bit-limitations
Tue Dec 11 14:46:53 [initandlisten] ** with --journal, the limit is lower
Tue Dec 11 14:46:53 [initandlisten]
Tue Dec 11 14:46:53 [initandlisten] db version v2.2.2, pdfile version 4.5
Tue Dec 11 14:46:53 [initandlisten] git version: d1b43b61a5308c4ad0679d34b262c5af9d664267
Tue Dec 11 14:46:53 [initandlisten] build info: Linux domU-12-31-39-01-70-B4 2.6.21.7-2.fc8xen # 1 SMP Fri Feb 15 12:39:36 EST 2008 i686 BOOST_LIB_VERSION = 1_49
Tue Dec 11 14:46:53 [initandlisten] options: {dbpath: "/ usr / local / mongodb / data / db /"}
Tue Dec 11 14:46:53 [initandlisten] Unable to check for journal files due to: boost :: filesystem :: basic_directory_iterator constructor: No such file or directory: "/ usr / local / mongodb / data / db / journal"
Tue Dec 11 14:46:53 [initandlisten] waiting for connections on port 27017
Tue Dec 11 14:46:53 [websvr] admin web console waiting for connections on port 28017
Tue Dec 11 14:47:11 [initandlisten] connection accepted from 127.0.0.1:48783 # 1 (1 connection now open)
Tue Dec 11 14:49:04 [initandlisten] connection accepted from 192.168.0.137:2869 # 2 (2 connections now open)
Tue Dec 11 14:49:04 [FileAllocator] allocating new datafile /usr/local/mongodb/data/db/temp.ns, filling with zeroes ...
Tue Dec 11 14:49:04 [FileAllocator] creating directory / usr / local / mongodb / data / db / _tmp
Tue Dec 11 14:49:05 [FileAllocator] done allocating datafile /usr/local/mongodb/data/db/temp.ns, size: 16MB, took 0.303 secs
Tue Dec 11 14:49:05 [FileAllocator] allocating new datafile /usr/local/mongodb/data/db/temp.0, filling with zeroes ...
Tue Dec 11 14:49:05 [FileAllocator] done allocating datafile /usr/local/mongodb/data/db/temp.0, size: 16MB, took 0.328 secs
Tue Dec 11 14:49:05 [FileAllocator] allocating new datafile /usr/local/mongodb/data/db/temp.1, filling with zeroes ...
Tue Dec 11 14:49:05 [conn2] build index temp.users {_id: 1}
Tue Dec 11 14:49:05 [conn2] build index done. Scanned 0 total records. 0 secs
Tue Dec 11 14:49:05 [conn2] insert temp.users keyUpdates: 0 locks (micros) w: 652433 652ms
Tue Dec 11 14:49:05 [conn2] end connection 192.168.0.137:2869 (1 connection now open)
Tue Dec 11 14:49:05 [FileAllocator] done allocating datafile /usr/local/mongodb/data/db/temp.1, size: 32MB, took 0.528 secs
Indicates that the setting is successful, do not close this interface at this time, you need to reopen a window to start Move mongo

 

Last login: Tue Dec 11 14:05:30 2012 from 192.168.0.137
[root @ localhost ~] # ls
anaconda-ks.cfg Desktop install.log install.log.syslog
[root @ localhost ~] # cd / usr / local
[root @ localhost local] # ls
bin gcc-4.1.2 gcc-install leveldb-1.5.0.tar.gz lib mongodb-linux-i686-2.0.8.tgz redis-1.2.6.tar.gz redis-2.6.6.tar.gz src
etc gcc-4.1.2.tar.gz include leveldb-1.7.0 libexec mongodb-linux-i686-2.2.2.tgz redis-2.4.14 sbin
games gcc-build leveldb-1.5.0 leveldb-1.7.0.tar.gz mongodb redis-1.2.6 redis-2.4.14.tar.gz share
[root @ localhost local] # cd mongodb
[root @ localhost mongodb] # ls
bin db GNU-AGPL-3.0 logs README THIRD-PARTY-NOTICES
[root @ localhost mongodb] # cd logs
[root @ localhost logs] # ls
[root @ localhost logs] # ls
[root @ localhost logs] #








[root @ localhost logs] # cd ..
[root @ localhost mongodb] # ./bin/mongo
MongoDB shell version: 2.2.2
connecting to: test
Welcome to the MongoDB shell.
For interactive help, type "help".
For more comprehensive documentation, see

http://docs.mongodb.org/

Questions? Try the support group

http://groups.google.com/group/mongodb-user

>












When this occurs, it means that the startup was successful, and then tested with java code:

/ **
 * MongoDbTest.java
 * Copyright (C) 2012
 * Created by: cuiran 2012-12-05 13:47:22
 * /
package com.wpndemo.mongodb;

import java.net.UnknownHostException;

import org.bson.types.ObjectId;

import com.mongodb.BasicDBObject;
import com.mongodb.DB;
import com.mongodb.DBCollection;
import com.mongodb.DBCursor;
import com.mongodb.DBObject;
import com.mongodb.Mongo;
import com.mongodb.MongoException;

/ **
 * TODO
 * @author cuiran
 * @version TODO
 * /
public class MongoDbTest {

private Mongo mg = null;
private DB db;
private DBCollection users;
The
/ **
* Initialization
* TODO
* /
public void init () {
try {
// mg = new Mongo ();
mg = new Mongo ("192.168.0.138", 27017);
} catch (UnknownHostException e) {
// TODO Auto-generated catch block
e.printStackTrace ();
} catch (MongoException e) {
// TODO Auto-generated catch block
e.printStackTrace ();
}
// Get temp DB will be created automatically if there is no default
db = mg.getDB ("temp");
// Obtain the Users Collection If it is not available by default, it will be created automatically
users = db.getCollection ("users");
The
The
The
}
The
/ **
* Destroy
* TODO
* /
public void destory () {
if (mg! = null) {
mg.close ();
}
mg = null;
db = null;
users = null;
System.gc ();
The
}
/ **
* <b> function: </ b> Query all data
* @author cuiran
* @createDate 2012-12-11 09:24:11
* /
public void queryAll () {
print ("Query all data of users");
// Db cursor
DBCursor cur = users.find ();
while (cur.hasNext ()) {
print (cur.next ());
}
}
The
/ **
*
* <b> function: </ b> add data
* @author cuiran
* @createDate 2012-12-11 09:25:23
* /
public void add () {
queryAll ();
The
print ("count:" + users.count ());
DBObject user = new BasicDBObject ();
user.put ("name", "cuiran1");
user.put ("age", 27);
The
// users.save (user);
// print (users.save (user) .getN ());
The
user.put ("sex", "Male");
print (users.save (user) .getN ());
The
The
print ("count:" + users.count ());
queryAll ();
The
}
/ **
*
* <b> function: </ b> delete data
* @author cuiran
* @createDate 2012-12-11 09:38:12
* /
public void remove () {
queryAll ();
print ("Remove id = 50c68da852c2e1adb70f6d29:" + users.remove (new BasicDBObject ("_ id", new ObjectId ("50c68da852c2e1adb70f6d29"))). getN ());
queryAll ();
}
The
public void print (Object o) {
System.out.println (o);
}
The
The
public void start () {
init ();
add ();
destory ();
// remove ();
// queryAll ();
The
The
}
The
/ **
* TODO
* @param args
* /
public static void main (String [] args) {
// TODO Auto-generated method stub
MongoDbTest t = new MongoDbTest ();
t.start ();
}

}
operation result:

 

Query all data of users
count: 0
0
count: 1
Query all data of users
{"_id": {"$ oid": "50c6d73952c25d5c9cec8c11"}, "name": "cuiran1", "age": 27, "sex": "Male"}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.