MongoDB quick start

  • 2020-05-06 11:57:41
  • OfStack

Interested in MongoDb document database, to install understanding.

To the official download version win http: / / www mongodb. org/display/DOCS/Downloads at present is the latest stable version of pathogen. Unzip to f:/sofr/ mongodb-win32-i386-1.2.4.

Start the mongod

 
F:\soft\mongodb-win32-i386-1.2.4>bin\mongod.exe --dbpath=f:/mongodb 
Mon Mar 08 11:13:17 Mongo DB : starting : pid = 0 port = 27017 dbpath = f:/mongodb master = 0 slave 
= 0 32-bit 

** NOTE: when using MongoDB 32 bit, you are limited to about 2 gigabytes of data 
** see http://blog.mongodb.org/post/137788967/32-bit-limitations for more 

Mon Mar 08 11:13:18 db version v1.2.4, pdfile version 4.5 
Mon Mar 08 11:13:18 git version: 5cf582d3d96b882c400c33e7670b811ccd47f477 
Mon Mar 08 11:13:18 sys info: windows (5, 1, 2600, 2, 'Service Pack 3') BOOST_LIB_VERSION=1_35 
Mon Mar 08 11:13:18 waiting for connections on port 27017 

--dbpath specifies the database directory, default is /data/db, win does not have /data/db directory, so directly double-click mongod will not start. The default port is 27017

I used the legacy-static version under linux because the source code compilation failed.

After the server starts, try it out with the client. It comes with a client (MongoDB shell). bin/mongo exe
 
F:\soft\mongodb-win32-i386-1.2.4>bin\mongo.exe 
MongoDB shell version: 1.2.4 
url: test 
connecting to: test 
type "exit" to exit 
type "help" for help 
> use test 
switched to db test 
> db.foo.save({a:1}) 
> db.foo.find() 
{ "_id" : ObjectId("4b946bc03f78000000001542"), "a" : 1 } 
> 

The mongod.exe backend can see the log.
MongoDB rich client, I use python try (see installation: http: / / api mongodb. org/python / 1.4% 2 B/installation. html). Install pymongo

 
easy_install pymongo 


 
from pymongo import Connection 
connection = Connection() 
db = connection.test 
for f in db.foo.find(): 
print "a=%s, _id=%s" % (f['a'], f['_id']) 

You can see the results. Es85en946bc03f78000000001542 a = 1.0, _id = 4. _id is the field inside mongo.

Its queries like sql are attractive...
Original text: http: / / blog. chenlb. com / 2010/03 / mongodb - quick - start. html


Related articles: