- 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.
推薦閱讀
- 火格局的時空變異及其在電網防火中的應用
- R Data Mining
- Dreamweaver CS3網頁制作融會貫通
- Windows 8應用開發實戰
- 嵌入式Linux上的C語言編程實踐
- Hands-On Cybersecurity with Blockchain
- OpenStack Cloud Computing Cookbook
- Deep Reinforcement Learning Hands-On
- Dreamweaver CS6精彩網頁制作與網站建設
- 空間機械臂建模、規劃與控制
- 軟件構件技術
- 網絡存儲·數據備份與還原
- 無人駕駛感知智能
- FreeCAD [How-to]
- Keras Reinforcement Learning Projects