Recently began to learn MONGO in the window installation has mastered, the operation is not difficult, the use of the work or the use of Linux in more. However, refer to some documentation after the installation is complete. Found a header error at startup MONGO
Finally, the problem is resolved by re-setting the path
Workaround: Enter the following command
[Root@localhost mongodb]#./bin/mongod-dbpath=/data/db
The interface will then 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 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]#
When this indicates a successful start, and then test with Java code:
/** * Mongodbtest.java * Copyright (C) 2012 * Create: 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;
/** * 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 If default does not automatically create DB=MG.GETDB ("temp"); Get the users Collection if default does not automatically create users=db.getcollection ("useRS ");
/** * Destroy * TODO/public void Destory () {if (mg!=null) {mg.close ();
} mg=null;
Db=null;
Users=null;
System.GC (); /** * <b>function:</b> Query all data * @author Cuiran * @createDate 2012-12-11 09:24:11/Public V
OID Queryall () {print ("Query all data for users");
DB cursor dbcursor cur=users.find ();
while (Cur.hasnext ()) {print (Cur.next ());
}/** * *<b>function:</b> add Data * @author Cuiran * @createDate 2012-12-11 09:25:23 *
public void Add () {Queryall ();
Print ("Count:" +users.count ());
DBObject user=new basicdbobject ();
User.put ("name", "Cuiran1");
User.put ("Age", 27);
Users.save (user);
Print (Users.save (user). GETN ());
User.put ("Sex", "male");
Print (Users.save (user). GETN ());
Print ("Count:" +users.count ());
Queryall (); /** * *<b>function:</b> Delete data * @author Cuiran * @createDatE 2012-12-11 09:38:12 */public void Remove () {Queryall (); Print (Delete id = 50c68da852c2e1adb70f6d29:) + users.remove (new Basicdbobject ("_id", New ObjectId ("
50c68da852c2e1adb70f6d29 ")). GETN ());
Queryall ();
public void print (Object o) {System.out.println (o);
public void Start () {init ();
Add ();
Destory ();
Remove ();
Queryall (); /** * Todo * @param args/public static void main (string[] args) {//Todo auto-generated method stub M
Ongodbtest t=new mongodbtest ();
T.start ();
}
}
Run Result:
Query all data for users
count:0
0
count:1
query all data for users
{"_id": {"$oid": "50c6d73952c25d5c9cec8c11"}, " Name ":" Cuiran1 "," Age ":", "Sex": "Male"}