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

  • Mastering MongoDB 3.x
  • Alex Giamas
  • 150字
  • 2021-08-20 10:10:52

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.

主站蜘蛛池模板: 阳东县| 新平| 石渠县| 揭东县| 乐业县| 太仆寺旗| 浦东新区| 长乐市| 湘潭市| 天等县| 乐陵市| 滁州市| 城市| 榆中县| 石门县| 磐石市| 沙田区| 吴旗县| 四会市| 琼结县| 凭祥市| 顺平县| 增城市| 华宁县| 康平县| 兴宁市| 麻江县| 河北省| 万全县| 宁明县| 措美县| 灵石县| 拜城县| 平舆县| 孟连| 永春县| 大洼县| 色达县| 伊通| 五大连池市| 福安市|