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

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.

主站蜘蛛池模板: 汤原县| 姜堰市| 革吉县| 西宁市| 南岸区| 凌云县| 高淳县| 晋江市| 措勤县| 永春县| 鲁甸县| 汝南县| 麻栗坡县| 金坛市| 昆明市| 鄂托克前旗| 星座| 新余市| 江门市| 渝北区| 广西| 扶余县| 同江市| 沽源县| 行唐县| 商河县| 万年县| 修水县| 满洲里市| 渭南市| 涡阳县| 仙居县| 嘉善县| 唐山市| 积石山| 阿巴嘎旗| 天水市| 治县。| 综艺| 合阳县| 永修县|