PHP extension to mongodb (fledgling)_PHP tutorial
Our php mongodb can also do almost all the functions that mysql and sqlserver can do. This article will introduce in detail
1. Operators
I believe everyone must know it, that is Equal to, greater than, less than, not equal to, greater than or equal to, less than or equal to, but these operators cannot be used directly in mongodb. The operator in mongodb is expressed like this:
(1) $gt > (greater than)
(2) $lt Equal to)
(4) $lt <= (less than or equal to)
(5) $ne != (not equal to)
(6) $in in (inclusive) nin not in (not included)
(8) $exists exist (whether the field exists)
(9) $inc Add value to a numeric field field
(10) $set It is equivalent to the set of sql field = value
(11) $unset It is to delete the field
(12) $push Append the value to the field. The field must be an array type. If the field does not exist, a new array type will be added. Go in
(13) $pushAll Same as $push, except that multiple values can be appended to an array field at one time
(14) $addToSet Adds a value to the array, and only adds it if the value is not in the array .
(15) $pop Delete the last value: { $pop : { field : 1 } } Delete the first value: { $pop : { field : -1 } } Note that only one value can be deleted, that is It says that you can only use 1 or -1, but not 2 or -2 to delete two items. Only mongodb 1.1 and later versions can use
(16) $pull to delete a value equal to value from the array field
(17) $pullAll Same as $pull, you can delete multiple values in the array at one time
(18) The $ operator is his own meaning, representing himself to find an item in the array based on conditions. This one is more difficult, so I won’t talk about it.
2. CURD Add, modify, read, delete
Add
Isn’t it very simple? Yes, it is that simple. It has no field restrictions. You can name it as you like and insert data
Modify
db.collection.update( { "count" : { $gt : 4 } } , { $set : { "test5" : "OK" } },true,false ); Records greater than 4 are only added to the first
db.collection.update( { "count" : { $gt : 5 } } , { $set : { "test5" : "OK"} },true,true ); Add all records greater than 5
You can see In the query, I used two different ways of writing it. This is why. In fact, it is the same as cooking. Adding different seasonings will result in different flavors in the dishes. Let me tell you the different functions of these two seasonings.
That is to say, for example, if we only want to check the detailed information of a specific piece of data, we can use findOne();
If we want to query a certain set of information, such as a news list, we can It can be used as find();
Then I think everyone will think that I want to sort this list. No problem mongodb will serve you wholeheartedly
db.collection.count(); //Get the total number of data
db.collection.limit(1); //Get data The starting position of
db.collection.skip(10); //Get the end position of the data
//In this way, we have implemented an operation of taking 10 pieces of data and sorting them.
Deletion has two operations remove() and drop()
distinct operation
db.user.distinct('name', {'age ': {$lt : 20}})
Oh! It’s too much to write in one breath, and it’s hard for everyone to digest after reading too much. That’s it for today. Tomorrow I will write about the operation of php on mongodb. Please look forward to it! I can’t write anymore, otherwise I will turn into a panda tomorrow. good night. have a good dream.

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

PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

To work on file upload we are going to use the form helper. Here, is an example for file upload.

CakePHP is an open-source framework for PHP. It is intended to make developing, deploying and maintaining applications much easier. CakePHP is based on a MVC-like architecture that is both powerful and easy to grasp. Models, Views, and Controllers gu

One of the major changes introduced in MySQL 8.4 (the latest LTS release as of 2024) is that the "MySQL Native Password" plugin is no longer enabled by default. Further, MySQL 9.0 removes this plugin completely. This change affects PHP and other app

Visual Studio Code, also known as VS Code, is a free source code editor — or integrated development environment (IDE) — available for all major operating systems. With a large collection of extensions for many programming languages, VS Code can be c

CakePHP is an open source MVC framework. It makes developing, deploying and maintaining applications much easier. CakePHP has a number of libraries to reduce the overload of most common tasks.

This tutorial demonstrates how to efficiently process XML documents using PHP. XML (eXtensible Markup Language) is a versatile text-based markup language designed for both human readability and machine parsing. It's commonly used for data storage an

The following resources contain additional information on CakePHP. Please use them to get more in-depth knowledge on this.
