1024programmer Mongodb Simple introduction to MongoDB

Simple introduction to MongoDB

Install MongoDB

$ sudo apt-get install mongodb

Will automatically install libpcrecpp0 libboost-system1.42.0
libboost-filesystem1.42.0

libboost-program-options1.42.0 libboost-thread1.42.0
xulrunner-2.0-mozjs

Mongodb-clients mongodb-server mongodb-dev mongodb and other dependent packages.

$ps aux | grep mongod

Install the Python language driver

$ sudo apt-get install python-setuptools

$ sudo easy_install pymongo

Configure MongoDB

$ sudo vim /etc/mongodb.conf

dbpath=’your datebase path’

logpath=’where to log’

logappend=true

bind_id=127.0.0.1

port=27017

mytestdb
Create Collection

Entering the database to create a coolection database is considered complete. use

db.createCollection(“mytestdb “, {capped:true, size:10000})
The unit is kb

Or db.runCommand({createCollection:” mytestdb “, capped:true,
size:100000} )

The capped parameter is to create a fixed-size database file. To ensure efficiency, mongo will occupy disk space when creating a collection to prevent fragmentation.

> db.createCollection(“mytestdb”, {capped:true,
size:10000})

> show collections

db.mytestdb.ensureIndex({age:-1})

Testing with Python

$python

>>> import pymongo

>>> cOnn=
pymongo.Connection(host=”localhost”, port=27017)

>>> db=conn.mytestdb

>>> for user in db.wfcoll.find({}):

…repr(user)

This article is from the internet and does not represent1024programmerPosition, please indicate the source when reprinting:https://www.1024programmer.com/simple-introduction-to-mongodb/

author: admin

Previous article
Next article

Leave a Reply

Your email address will not be published. Required fields are marked *

Contact Us

Contact us

181-3619-1160

Online consultation: QQ交谈

E-mail: [email protected]

Working hours: Monday to Friday, 9:00-17:30, holidays off

Follow wechat
Scan wechat and follow us

Scan wechat and follow us

Follow Weibo
Back to top
首页
微信
电话
搜索