安装MongoDB 开发环境PyMongo
pymongo是一个驱动程序,用Python编写的高性能,文件为基础的数据库。
pymongo是一个驱动程序,,用Python编写的高性能,文件为基础的数据库。
下载并安装。
[monogdb@localhost bin]$wget #md5=12e12163e6cc22993808900fb9629252
--21:21:18--
正在解析主机 pypi.python.org... 82.94.164.168, 2001:888:2000:d::a8
Connecting to pypi.python.org|82.94.164.168|:80... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:146895 (143K) [application/x-gzip]
Saving to: `pymongo-1.9.tar.gz'
100%[============================================================================================>] 146,895 66.9K/s in 2.1s
21:21:21 (66.9 KB/s) - `pymongo-1.9.tar.gz' saved [146895/146895]
[monogdb@localhost bin]$tar zxvf pymongo-1.9.tar.gz
pymongo-1.9/
pymongo-1.9/doc/
pymongo-1.9/ez_setup.py/
pymongo-1.9/pymongo/
pymongo-1.9/setup.cfg
pymongo-1.9/setup.py
......
pymongo-1.9/bson/timestamp.py
pymongo-1.9/bson/tz_util.py
[monogdb@localhost bin]$ cd pymongo-1.9
[monogdb@localhost pymongo-1.9]$ ls
bson ez_setup.py LICENSE PKG-INFO pymongo.egg-info setup.cfg test
doc gridfs MANIFEST.in pymongo README.rst setup.py tools
第一次执行安装的时候报错,权限不够
[monogdb@localhost pymongo-1.9]$ python setup.py install
running install
error: can't create or remove files in install directory
The following error occurred while trying to add or remove files in the
installation directory:
[Errno 13] Permission denied: '/usr/lib64/python2.4/site-packages/test-easy-install-11661.write-test'
The installation directory you specified (via --install-dir, --prefix, or
the distutils default setting) was:
/usr/lib64/python2.4/site-packages/
Perhaps your account does not have write access to this directory? If the
installation directory is a system-owned directory, you may need to sign in
as the administrator or "root" account. If you do not have administrative
access to this machine, you may wish to choose a different installation
directory, preferably one that is listed in your PYTHONPATH environment
variable.
以root权限给monogdb赋予访问/usr/lib64/python2.4/site-packages/的权限:
[root@localhost ~]#chown monogdb:monogdb /usr/lib64/python2.4/site-packages/
再次安装。。
[monogdb@localhost pymongo-1.9]$python setup.py install
running install
running bdist_egg
running egg_info
writing pymongo.egg-info/PKG-INFO
writing top-level names to pymongo.egg-info/top_level.txt
writing dependency_links to pymongo.egg-info/dependency_links.txt
Processing pymongo-1.9-py2.4-linux-x86_64.egg
creating /usr/lib64/python2.4/site-packages/pymongo-1.9-py2.4-linux-x86_64.egg
Extracting pymongo-1.9-py2.4-linux-x86_64.egg to /usr/lib64/python2.4/site-packages
Adding pymongo 1.9 to easy-install.pth file
Installed /usr/lib64/python2.4/site-packages/pymongo-1.9-py2.4-linux-x86_64.egg
Processing dependencies for pymongo==1.9
Finished processing dependencies for pymongo==1.9
测试python环境中与monogdb的交互。
[monogdb@localhost pymongo-1.9]$ python
Python 2.4.3 (#1, Jan 21 2009, 01:11:33)
[GCC 4.1.2 20071124 (Red Hat 4.1.2-42)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import pymongo
>>> conn = pymongo.Connection(host="127.0.0.1")
>>> db=conn.test
>>> db
Database(Connection('127.0.0.1', 27017), u'test')
>>> str={"id":1,'val':"hello monogdb"}
>>> db.test.save(str)
ObjectId('4e3fe5d8e138232e61000000')
>>> cursor = db.test.find()
>>> for i in cursor:
... print i
...
{u'_id': ObjectId('4e3fe5d8e138232e61000000'), u'id': 1, u'val': u'hello monogdb'}
>>>
成功!!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

It is recommended to use the latest version of MongoDB (currently 5.0) as it provides the latest features and improvements. When selecting a version, you need to consider functional requirements, compatibility, stability, and community support. For example, the latest version has features such as transactions and aggregation pipeline optimization. Make sure the version is compatible with the application. For production environments, choose the long-term support version. The latest version has more active community support.

Node.js is a server-side JavaScript runtime, while Vue.js is a client-side JavaScript framework for creating interactive user interfaces. Node.js is used for server-side development, such as back-end service API development and data processing, while Vue.js is used for client-side development, such as single-page applications and responsive user interfaces.

With the development of the Internet, people's lives are becoming more and more digital, and the demand for personalization is becoming stronger and stronger. In this era of information explosion, users are often faced with massive amounts of information and have no choice, so the importance of real-time recommendation systems has become increasingly prominent. This article will share the experience of using MongoDB to implement a real-time recommendation system, hoping to provide some inspiration and help to developers. 1. Introduction to MongoDB MongoDB is an open source NoSQL database known for its high performance, easy scalability and flexible data model. Compared to biography

The data of the MongoDB database is stored in the specified data directory, which can be located in the local file system, network file system or cloud storage. The specific location is as follows: Local file system: The default path is Linux/macOS:/data/db, Windows: C:\data\db. Network file system: The path depends on the file system. Cloud Storage: The path is determined by the cloud storage provider.

The MongoDB database is known for its flexibility, scalability, and high performance. Its advantages include: a document data model that allows data to be stored in a flexible and unstructured way. Horizontal scalability to multiple servers via sharding. Query flexibility, supporting complex queries and aggregation operations. Data replication and fault tolerance ensure data redundancy and high availability. JSON support for easy integration with front-end applications. High performance for fast response even when processing large amounts of data. Open source, customizable and free to use.

MongoDB is a document-oriented, distributed database system used to store and manage large amounts of structured and unstructured data. Its core concepts include document storage and distribution, and its main features include dynamic schema, indexing, aggregation, map-reduce and replication. It is widely used in content management systems, e-commerce platforms, social media websites, IoT applications, and mobile application development.

The MongoDB database file is located in the MongoDB data directory, which is /data/db by default, which contains .bson (document data), ns (collection information), journal (write operation records), wiredTiger (data when using the WiredTiger storage engine ) and config (database configuration information) and other files.

On Linux/macOS: Create the data directory and start the "mongod" service. On Windows: Create the data directory and start the MongoDB service from Service Manager. In Docker: Run the "docker run" command. On other platforms: Please consult the MongoDB documentation. Verification method: Run the "mongo" command to connect and view the server version.
