日期:2014-05-16  浏览次数:20463 次

mongodb(4)Latest Version on MAC and Setup Replication

mongodb(4)Latest Version on MAC and Setup Replication

1. Installation on MAC
Get the latest file from here:?http://fastdl.mongodb.org/osx/mongodb-osx-x86_64-2.4.7.tgz
unzip the file and find a right place
>cd /Users/carl/tool/mongodb-osx-x86_64-2.4.7?
>sudo ln -s /Users/carl/tool/mongodb-osx-x86_64-2.4.7 /opt/mongodb-2.4.7
>sudo ln -s /opt/mongodb-2.4.7 /opt/mongodb

By default, mongo writes data to the /data/db directory.
>sudo mkdir -p /data/db
>sudo chown carl /data/db

If this path is not what you want, you can use --dbpath option to mongod?
>sudo vi ~/.profile
export PATH=/opt/mongodb/bin:$PATH
>. ~/.profile?

>vi mongodb.conf
fork = true ?//daemon bind_ip = 127.0.0.1 port = 27017 quiet = true ? ? ? ? dbpath = /data/db/mongodb logpath = /var/log/mongodb/mongod.log logappend = true journal = true

Start the Server
>mongod -f mongodb.conf

>ps -ef | grep mongo

Try with Client to connect to it.
>mongo
mongo>db.test.save({a:1,b:2})
mongo>db.test.find()
{ "_id" : ObjectId("52684c242cb20b7935c6537d"), "a" : 1, "b" : 2 }

Some Grammar of SQL
SQL Statement ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? Mongo Statement?
create table users ? ? ? ? ? ? ? ? ? ? ? ? ? ? db.createCollection("users");?