search
HomeWeb Front-endJS TutorialPHP extension to mongodb (first acquaintance)_javascript skills

Under the coercion of the blogger, I would like to share a little with you. I hereby declare that the blogger is very simple and honest. This is just a coercion, and there is absolutely no inducement.
Since there is less Chinese information related to mongodb, I will continue to share it with you if I have the opportunity. I hope this little sharing can bring something to everyone. Let’s get back to the point, please read on.

Why do you say "we met each other for the first time"? Because the data storage format of mongodb is a kind of data storage format. MongoDB's document structure is BJSON format (full name of BJSON: BinaryJSON), and the BJSON format itself supports saving data in binary format. , so the binary format data of the file can be saved directly into the MongoDB document structure.

MongoDB is composed of three levels: database, collection, and document object. Correspondence between
and relational database:

Relational database MongoDB database

Database database
table collection

Row document
can be used in MongoDB When creating an index, there is a default hidden field _id in the collection.

Installation and use

Install mongodb under windows and simply use mongodb command
1. Download and unzip the file
Go to the official website to download the appropriate version http:/ /www.mongodb.org/downloads
For example: http://fastdl.mongodb.org/win32/mongodb-win32-i386-2.2.1.zip
Unzip and place it under the corresponding drive letter, for example : D:mongodb
2. Installation
1. Add the bin directory to the environment variable D:mongodbbin
2. Create a data folder under D:mongodb to store data. You also need to create a db folder under the data file. Without the db folder, mongodb cannot start normally
3. Simple method to start mongodb:
Enter the bin directory

Copy code The code is as follows:

C:Documents and Settingsme>D:
D:>cd mongodb/bin
D: mongodbbin>mongod –dbpath D:/mongodb/data
D:mongodbbin>mongod –dbpath D:/mongodb/data

The following content is displayed:
Sun Jan 16 14:56:03 MongoDB starting: pid=860 port=27017 dbpath=D:/mongodb/d
ata 32-bit

** NOTE: when using MongoDB 32 bit, you are limited to about 2 gigabytes of data

** see http://blog.mongodb.org/post/137788967/32-bit-limitations

Sun Jan 16 14:56:03 db version v2.2.1, pdfile version 4.5
Sun Jan 16 14:56:03 git version: 0eb017e9b2828155a67c5612183337b89e12e291
Sun Jan 16 14:56:03 sys info: windows (5, 1, 2600, 2, 'Service Pack 3 ′) BOOST_LI
B_VERSION=1_35
Sun Jan 16 14:56:03 [initandlisten] waiting for connections on port 27017
Sun Jan 16 14:56:03 [websvr] web admin interface listening on port 28017

Note: You must first create the data folder and execute it in the bin directory. The default connection port of the mongoDB server is 27017

2. Add it to the registry to start as a Windows service. Like mysql, the service will be automatically started when Windows is started. Go to the bin directory and execute
Copy code The code is as follows:

D:mongodbbin>mongod --logpath D:mongodbloglog1.log --logappend
-- dbpath D:mongodbdata --directoryperdb --serviceName mongodb –install

After completion, output the following content (anti-virus software such as 360 will block it and need to be allowed to pass)
all output going to: D:mongodblogslog1 .log
Creating service mongodb
Service creation successful.
Service can be started from the command line via 'net start “mongodb″'.

D:mongodbbin>

Among them: loglog1.log log is output in append mode, –serviceName mongodb is the service name
Start MongoDB: net start mongodb
Stop MongoDB: net stop mongodb
Note: Restart after adding to the registry The computer can see that it has been started in the service item, but the service is still not started. When restarting the service, it is found that it is blocked by 360 Security Guards and needs to be confirmed again before it can be started.

3. A simple command to use mongodb. Go to the bin command and execute mongo.exe to enter the management interface. The default is to enter the test account.
Copy code The code is as follows:

D:mongodbbin>mongo.exe
MongoDB shell version: 2.2.1
connecting to: test
> show dbs;
admin
local

> help;View command prompt


3. Next, the same operation as for all databases requires adding a user’s defense permission
But the user created at this time does not have the permission to view the collection. What to do! In fact, it's easy to handle. I've already had a headache for everyone, so students who can persist in seeing this with their heart won't have any more headaches.
Execute the following command in the mongo.exe management interface you just entered

Copy the code The code is as follows:

>use admin
>db.auth("sa","sa")
>use web
>show collections

This time It's clear now.

4. MongoDB can create a database using use as follows: use web; This will create a database
Switch to the web database. If it does not exist, it will automatically be inserted after the data is inserted. Create one, and you can see a new web folder in the data directory
Copy the code The code is as follows:

> use web;

switched to db web
> db.my.save({a:10}); Save a message to collection my if it does not exist collection will automatically create a
> db.my.find(); retrieve all records
{ “_id” : ObjectId(“4d32c9204e6100000000691e”), “a” : 10 }
> show collections;
my
system.indexes
>exit;Exit

The installation and user permission settings of Mongodb have ended.
The following introduces several graphics management tools
1. Use the graphics management tool "MongoVUE 0.9.7.2"


You can see it after entering


2. A more recommended management software is "rockmongo"
It needs the support of PHP operating environment. I prefer it because PHP programmers have a ready-made environment and don't need to use it in vain, haha .
(1). Download a rockmongo, unzip it and put it in the web directory. Download address: http://rockmongo.com/downloads
If you don’t have a PHP operating environment but want to use rockmongo, you can Integrate package download in the download address.
(2). Download a php_mongo.dll that supports mongodb. Download address: https://github.com/mongodb/mongo-php-driver/downloads
(3). Add it to php.ini This line of code extension=php_mongo.dll Then restart apache and check php_info


means the installation has been successful
(4). Enter the address of rockmongo in the browser, a login box will appear, and you can log in. The default user is: admin Password: admin
There are many other tools, you can explore slowly.

Statement
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
From Websites to Apps: The Diverse Applications of JavaScriptFrom Websites to Apps: The Diverse Applications of JavaScriptApr 22, 2025 am 12:02 AM

JavaScript is widely used in websites, mobile applications, desktop applications and server-side programming. 1) In website development, JavaScript operates DOM together with HTML and CSS to achieve dynamic effects and supports frameworks such as jQuery and React. 2) Through ReactNative and Ionic, JavaScript is used to develop cross-platform mobile applications. 3) The Electron framework enables JavaScript to build desktop applications. 4) Node.js allows JavaScript to run on the server side and supports high concurrent requests.

Python vs. JavaScript: Use Cases and Applications ComparedPython vs. JavaScript: Use Cases and Applications ComparedApr 21, 2025 am 12:01 AM

Python is more suitable for data science and automation, while JavaScript is more suitable for front-end and full-stack development. 1. Python performs well in data science and machine learning, using libraries such as NumPy and Pandas for data processing and modeling. 2. Python is concise and efficient in automation and scripting. 3. JavaScript is indispensable in front-end development and is used to build dynamic web pages and single-page applications. 4. JavaScript plays a role in back-end development through Node.js and supports full-stack development.

The Role of C/C   in JavaScript Interpreters and CompilersThe Role of C/C in JavaScript Interpreters and CompilersApr 20, 2025 am 12:01 AM

C and C play a vital role in the JavaScript engine, mainly used to implement interpreters and JIT compilers. 1) C is used to parse JavaScript source code and generate an abstract syntax tree. 2) C is responsible for generating and executing bytecode. 3) C implements the JIT compiler, optimizes and compiles hot-spot code at runtime, and significantly improves the execution efficiency of JavaScript.

JavaScript in Action: Real-World Examples and ProjectsJavaScript in Action: Real-World Examples and ProjectsApr 19, 2025 am 12:13 AM

JavaScript's application in the real world includes front-end and back-end development. 1) Display front-end applications by building a TODO list application, involving DOM operations and event processing. 2) Build RESTfulAPI through Node.js and Express to demonstrate back-end applications.

JavaScript and the Web: Core Functionality and Use CasesJavaScript and the Web: Core Functionality and Use CasesApr 18, 2025 am 12:19 AM

The main uses of JavaScript in web development include client interaction, form verification and asynchronous communication. 1) Dynamic content update and user interaction through DOM operations; 2) Client verification is carried out before the user submits data to improve the user experience; 3) Refreshless communication with the server is achieved through AJAX technology.

Understanding the JavaScript Engine: Implementation DetailsUnderstanding the JavaScript Engine: Implementation DetailsApr 17, 2025 am 12:05 AM

Understanding how JavaScript engine works internally is important to developers because it helps write more efficient code and understand performance bottlenecks and optimization strategies. 1) The engine's workflow includes three stages: parsing, compiling and execution; 2) During the execution process, the engine will perform dynamic optimization, such as inline cache and hidden classes; 3) Best practices include avoiding global variables, optimizing loops, using const and lets, and avoiding excessive use of closures.

Python vs. JavaScript: The Learning Curve and Ease of UsePython vs. JavaScript: The Learning Curve and Ease of UseApr 16, 2025 am 12:12 AM

Python is more suitable for beginners, with a smooth learning curve and concise syntax; JavaScript is suitable for front-end development, with a steep learning curve and flexible syntax. 1. Python syntax is intuitive and suitable for data science and back-end development. 2. JavaScript is flexible and widely used in front-end and server-side programming.

Python vs. JavaScript: Community, Libraries, and ResourcesPython vs. JavaScript: Community, Libraries, and ResourcesApr 15, 2025 am 12:16 AM

Python and JavaScript have their own advantages and disadvantages in terms of community, libraries and resources. 1) The Python community is friendly and suitable for beginners, but the front-end development resources are not as rich as JavaScript. 2) Python is powerful in data science and machine learning libraries, while JavaScript is better in front-end development libraries and frameworks. 3) Both have rich learning resources, but Python is suitable for starting with official documents, while JavaScript is better with MDNWebDocs. The choice should be based on project needs and personal interests.

See all articles

Hot AI Tools

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.

Undress AI Tool

Undress AI Tool

Undress images for free

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

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment