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

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.

主站蜘蛛池模板: 固镇县| 宝清县| 鹤峰县| 涿鹿县| 进贤县| 余江县| 松潘县| 昌吉市| 青阳县| 长武县| 财经| 轮台县| 汉源县| 沈丘县| 思南县| 安康市| 辛集市| 马山县| 余姚市| 保亭| 芒康县| 衡山县| 厦门市| 安远县| 中超| 宕昌县| 万载县| 遂平县| 江北区| 林芝县| 平谷区| 南投县| 若尔盖县| 千阳县| 秀山| 平凉市| 炉霍县| 庆云县| 金坛市| 义马市| 闽清县|