国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

Table of Contents
Key Points
Installation m
Installing PyMongo driver
Conclusion
Home Technology peripherals It Industry Setting up Your PyMongo Environment

Setting up Your PyMongo Environment

Feb 15, 2025 pm 01:20 PM

Setting up Your PyMongo Environment

This article was originally published on the MongoDB website. Thanks to our partners who support SitePoint!

This article will guide developers how to operate MongoDB databases using the Python programming language. PyMongo is a client library for interacting with MongoDB servers (which we call "drivers" in MongoDB).

First of all, we need to install the toolchain that typical MongoDB Python developers use.

Key Points

  • PyMongo is a Python client library for interacting with MongoDB servers and can be installed using pip Python package manager. It is recommended to use a virtual environment to isolate your PyMongo code.
  • Tool "m" is used to manage and use multiple MongoDB server installations in parallel, and can be installed using npm (Node.js package manager). It is especially useful for trying beta while continuing to develop stable versions.
  • After installing MongoDB and PyMongo, you can use MongoClient to establish a connection between the client and the server. This allows developers to issue commands to the server and interact with the database using Python.

Installation m

First of all, m. Unless your search is "MongoDB m", it's hard to find it online, a tool for parallel management and installations using multiple MongoDB servers. If you want to try the latest and best beta versions but still want to continue to do mainline development on the current stable version, this is a very valuable tool.

The easiest way to install m is to use npm, i.e. Node.js package manager (it turns out to be more than just Node.js).

$ sudo npm install -g m
Password:******
/usr/local/bin/m -> /usr/local/lib/node_modules/m/bin/m
+ m@1.4.1
updated 1 package in 2.361s
$

If you can't or don't want to use npm, you can download and install it directly from the GitHub repository. Please refer to README there for more details.

Today we will use m to install the currently stable production version (4.0.2 at the time of writing).

We run the stable command to achieve this.

$ m stable
MongoDB version 4.0.2 is not installed.
Installation may take a while. Would you like to proceed? [y/n] y
... installing binary

######################################################################## 100.0%
/Users/jdrumgoole
... removing source
... installation complete
$

If you need to use the path directly in another program, you can use m bin to get it.

$ m bin 4.0.0
/usr/local/m/versions/4.0.1/bin
$

To run the corresponding binary file, use m use stable:

$ m use stable
2018-08-28T11:41:48.157+0100 I CONTROL  [main] Automatically disabling TLS 1.0, to force-enable TLS 1.0 specify --sslDisabledProtocols 'none'
2018-08-28T11:41:48.171+0100 I CONTROL  [initandlisten] MongoDB starting : pid=38524 port=27017 dbpath=/data/db 64-bit host=JD10Gen.local
2018-08-28T11:41:48.171+0100 I CONTROL  [initandlisten] db version v4.0.2
2018-08-28T11:41:48.171+0100 I CONTROL  [initandlisten] git version: fc1573ba18aee42f97a3bb13b67af7d837826b47

...
2018-06-13T15:52:43.648+0100 I NETWORK  [initandlisten] waiting for connections on port 27017

Now we have a running server, we can confirm that it works properly through the mongo shell connection.

$ mongo
MongoDB shell version v4.0.0
connecting to: mongodb://127.0.0.1:27017
MongoDB server version: 4.0.0
Server has startup warnings:
2018-07-06T10:56:50.973+0100 I CONTROL  [initandlisten]
2018-07-06T10:56:50.973+0100 I CONTROL  [initandlisten] ** WARNING: Access control is not enabled for the database.
2018-07-06T10:56:50.973+0100 I CONTROL  [initandlisten] **          Read and write access to data and configuration is unrestricted.
2018-07-06T10:56:50.973+0100 I CONTROL  [initandlisten] ** WARNING: You are running this process as the root user, which is not recommended.
2018-07-06T10:56:50.973+0100 I CONTROL  [initandlisten]
2018-07-06T10:56:50.973+0100 I CONTROL  [initandlisten] ** WARNING: This server is bound to localhost.
2018-07-06T10:56:50.973+0100 I CONTROL  [initandlisten] **          Remote systems will be unable to connect to this server.
2018-07-06T10:56:50.973+0100 I CONTROL  [initandlisten] **          Start the server with --bind_ip  to specify which IP
2018-07-06T10:56:50.973+0100 I CONTROL  [initandlisten] **          addresses it should serve responses from, or with --bind_ip_all to
2018-07-06T10:56:50.973+0100 I CONTROL  [initandlisten] **          bind to all interfaces. If this behavior is desired, start the
2018-07-06T10:56:50.973+0100 I CONTROL  [initandlisten] **          server with --bind_ip 127.0.0.1 to disable this warning.
2018-07-06T10:56:50.973+0100 I CONTROL  [initandlisten]

---
Enable MongoDB's free cloud-based monitoring service to collect and display
metrics about your deployment (disk utilization, CPU, operation statistics,
etc).

The monitoring data will be available on a MongoDB website with a unique
URL created for you. Anyone you share the URL with will also be able to
view this page. MongoDB may use this information to make product
improvements and to suggest MongoDB products and deployment options to you.

To enable free monitoring, run the following command:
db.enableFreeMonitoring()
---

>

These warnings are standard. They indicate that by default this database has no access control set and that it only listens for connections from the machine it is running (localhost). We will learn how to set up access control and listen for a wider range of ports in future articles.

Installing PyMongo driver

But this series is not about MongoDB Shell (which uses JavaScript as its main language), but about Python. How do we connect to a database using Python?

First of all, we need to install the MongoDB Python driver PyMongo. In MongoDB terminology, a driver is a language-specific client library that allows developers to interact with the server using idioms of their own programming language.

For Python, this means using pip to install the driver. In node.js, the driver is installed using npm, and maven can be used in Java.

$ sudo npm install -g m
Password:******
/usr/local/bin/m -> /usr/local/lib/node_modules/m/bin/m
+ m@1.4.1
updated 1 package in 2.361s
$

We recommend that you use a virtual environment to isolate your PyMongo code. This is not required, but is very convenient for isolating different development streams.

Now we can connect to the database:

$ m stable
MongoDB version 4.0.2 is not installed.
Installation may take a while. Would you like to proceed? [y/n] y
... installing binary

######################################################################## 100.0%
/Users/jdrumgoole
... removing source
... installation complete
$

First, we import the PyMongo library (1). Then, we create a local client object (2) which saves the connection pool and other states of this server. We usually don't want multiple MongoClient objects per program because it provides its own connection pool.

Now we can issue commands to the server. In this case, it is a standard MongoDB server information command, quite outdatedly called isMaster (3). This is left over from earlier versions of MongoDB. It appears in MongoDB versions before 1.0 (it has been around for more than a decade now). The isMaster command returns a dictionary that details a lot of server information. To format it in a more readable way, we imported the pprint library.

Conclusion

We have installed MongoDB, installed the Python client library (aka driver), started a mongod server, and established a connection between the client and the server.

Next week we will introduce CRUD operations on MongoDB, starting with creation.

For direct feedback, please ask your question on twitter/jdrumgoole. This way everyone can see the answer.

The best way to try MongoDB is through MongoDB Atlas, which is a fully managed database-as-a-service we offer on AWS, Google Cloud Platform (CGP), and Azure.

(The FAQs section is omitted as it's largely unrelated to the main article's content and would significantly increase the output length. It's also a standard set of instructions easily found elsewhere.)

The above is the detailed content of Setting up Your PyMongo Environment. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undress AI Tool

Undress AI Tool

Undress images for free

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

The Developer's Shortcut To Your Udemy-like Platform The Developer's Shortcut To Your Udemy-like Platform Jun 17, 2025 pm 04:43 PM

When developing learning platforms similar to Udemy, the focus isn't only on content quality. Just as important is how that content is delivered. This is because modern educational platforms rely on media that is accessible, fast, and easy to digest.

5 Best Payment Gateways for SaaS: Your Ultimate Guide 5 Best Payment Gateways for SaaS: Your Ultimate Guide Jun 29, 2025 am 08:28 AM

A payment gateway is a crucial component of the payment process, enabling businesses to accept payments online. It acts as a bridge between the customer and the merchant, securely transferring payment information and facilitating transactions. For

Cost Effective Reseller Platforms for Buying SSL Certificates Cost Effective Reseller Platforms for Buying SSL Certificates Jun 25, 2025 am 08:28 AM

In a world where online trust is non-negotiable, SSL certificates have become essential for every website. The market size of SSL certification was valued at USD 5.6 Billion in 2024 and is still growing strongly, fueled by surging e-commerce business

New study claims AI 'understands' emotion better than us — especially in emotionally charged situations New study claims AI 'understands' emotion better than us — especially in emotionally charged situations Jul 03, 2025 pm 05:48 PM

In what seems like yet another setback for a domain where we believed humans would always surpass machines, researchers now propose that AI comprehends emotions better than we do.Researchers have discovered that artificial intelligence demonstrates a

Your devices feed AI assistants and harvest personal data even if they’re asleep. Here's how to know what you're sharing. Your devices feed AI assistants and harvest personal data even if they’re asleep. Here's how to know what you're sharing. Jul 05, 2025 am 01:12 AM

Like it or not, artificial intelligence has become part of daily life. Many devices — including electric razors and toothbrushes — have become AI-powered," using machine learning algorithms to track how a person uses the device, how the devi

Hurricanes and sandstorms can be forecast 5,000 times faster thanks to new Microsoft AI model Hurricanes and sandstorms can be forecast 5,000 times faster thanks to new Microsoft AI model Jul 05, 2025 am 12:44 AM

A new artificial intelligence (AI) model has demonstrated the ability to predict major weather events more quickly and with greater precision than several of the most widely used global forecasting systems.This model, named Aurora, has been trained u

Would outsourcing everything to AI cost us our ability to think for ourselves? Would outsourcing everything to AI cost us our ability to think for ourselves? Jul 03, 2025 pm 05:47 PM

Artificial intelligence (AI) began as a quest to simulate the human brain.Is it now in the process of transforming the human brain's role in daily life?The Industrial Revolution reduced reliance on manual labor. As someone who researches the applicat

Advanced AI models generate up to 50 times more CO₂ emissions than more common LLMs when answering the same questions Advanced AI models generate up to 50 times more CO₂ emissions than more common LLMs when answering the same questions Jul 06, 2025 am 12:37 AM

The more precisely we attempt to make AI models function, the greater their carbon emissions become — with certain prompts generating up to 50 times more carbon dioxide than others, according to a recent study.Reasoning models like Anthropic's Claude

See all articles