- 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.
推薦閱讀
- 我的J2EE成功之路
- Spark編程基礎(Scala版)
- 3D Printing with RepRap Cookbook
- CSS全程指南
- Associations and Correlations
- 計算機網絡技術基礎
- Kubernetes for Serverless Applications
- 云原生架構進階實戰
- Linux內核精析
- Mastering pfSense
- 水晶石影視動畫精粹:After Effects & Nuke 影視后期合成
- 納米集成電路制造工藝(第2版)
- PostgreSQL High Performance Cookbook
- 工業機器人應用系統三維建模
- Arduino創意機器人入門:基于Mind+