- 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.
推薦閱讀
- Hands-On Intelligent Agents with OpenAI Gym
- 智能傳感器技術與應用
- 數據挖掘方法及天體光譜挖掘技術
- Supervised Machine Learning with Python
- 網絡安全與防護
- Machine Learning with the Elastic Stack
- 在實戰中成長:C++開發之路
- 電腦上網入門
- 基于Proteus的單片機應用技術
- 人工智能:智能人機交互
- Practical Network Automation
- 輸送技術、設備與工業應用
- 智能座艙之車載機器人交互設計與開發
- 多傳感器數據智能融合理論與應用
- Pentaho Data Integration Beginner's Guide(Second Edition)