官术网_书友最值得收藏!

Connecting using Python

A strong contender to Ruby and Rails is Python with Django. Similar to Mongoid there is MongoEngine and an official MongoDB low level driver, PyMongo.

Installing PyMongo can be done using pip or easy_install:

python -m pip install pymongo
python -m easy_install pymongo

Then in our class we can connect to a database:

>>> from pymongo import MongoClient
>>> client = MongoClient()

Connecting to a replica set needs a set of seed servers for the client to find out what the primary, secondary, or arbiter nodes in the set are:

client = pymongo.MongoClient('mongodb://user:passwd@node1:p1,node2:p2/?replicaSet=rsname')

Using the connection string URL we can pass a username/password and replicaSet name all in a single string. Some of the most interesting options for the connection string URL are presented in the next section.

Connecting to a shard requires the server host and IP for the mongo router, which is the mongos process.

主站蜘蛛池模板: 黄山市| 万安县| 开平市| 达尔| 鹤峰县| 皮山县| 那曲县| 武城县| 奎屯市| 克东县| 临沧市| 青岛市| 建始县| 文水县| 镇巴县| 南靖县| 永康市| 新兴县| 宝山区| 清水县| 潼南县| 承德县| 怀集县| 崇左市| 大庆市| 泸西县| 永修县| 安徽省| 嘉峪关市| 涟源市| 清新县| 翁牛特旗| 临湘市| 鲜城| 南雄市| 高青县| 红安县| 密云县| 甘南县| 桃园县| 巴林右旗|