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 knows the operators, which are 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 operators in mongodb are expressed as follows:
(1) $gt > (greater than)
(2) $lt (3) $gte >= (greater than or equal to)
(4) $lt (Whether the field exists)
(9) $inc Append to the field. The field must be an array type. If the field does not exist, a new array type will be added.
(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 when 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, only You can use 1 or -1, but not 2 or -2 to delete two items. Mongodb 1.1 and later versions can only 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) $ operator It's his own meaning, and represents himself as an item in the array found based on conditions. This one is more difficult, so I won’t talk about it.
2. CURD Add, modify, read, delete
Add
Copy code The code is as follows:
db.collection->insert({'name' => 'caleng', 'email' => 'admin#admin .com'});
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
Copy code The code is as follows:
db.collection.update( { "count" : { $gt : 1 } } , { $set : { "test2" : "OK"} } ); Only the first record greater than 1 is updated
db.collection.update( { "count" : { $gt : 3 } } , { $set : { "test2" : "OK"} },false,true ); All records greater than 3 have been updated
db.collection.update( { "count" : { $gt : 4 } } , { $set : { "test5" : "OK"} },true,false ); Records greater than 4 are only added to the first one
db.collection.update( { "count" : { $ gt : 5 } } , { $set : { "test5" : "OK"} },true,true ); Add all records greater than 5
Query
Copy code The code is as follows:
db.collection.find(array ('name' => 'bailing'), array('email'=>'email@qq.com'))
db.collection.findOne(array('name' => 'bailing'), array ('email''email@qq.com'))
You can see that I used two different ways of writing the query. This is why. In fact, it is the same as cooking. Different seasonings are added and stir-fried. The dishes are different in taste. Let me tell you the different functions of these two seasonings.
findOne() only returns a document object, and find() returns a collection list.
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 use find() );
Then I think everyone will think that I want to sort this list, no problem mongodb will serve you wholeheartedly
Copy the code The code is as follows:
db.collection.find().sort({age:1 }); //Arrange in positive order by age
db.collection.find().sort({age:-1}); //Arrange in reverse order by age
db.collection.count(); //Get the total number of data
db.collection.limit(1); //Get the starting position of the data
db.collection.skip(10); //Get the ending position of the data
//In this way we have implemented a method of taking 10 pieces of data and sorting them operate.
Delete
Deletion has two operations remove() and drop()
Copy code The code is as follows:
db.collection.remove({"name",'jerry'}) //Delete specific data
db.collection.drop () //Delete all data in the collection
distinct operation
Copy code The code is as follows:
db.user.distinct('name', {'age': {$lt : 20}})

What’s still popular is the ease of use, flexibility and a strong ecosystem. 1) Ease of use and simple syntax make it the first choice for beginners. 2) Closely integrated with web development, excellent interaction with HTTP requests and database. 3) The huge ecosystem provides a wealth of tools and libraries. 4) Active community and open source nature adapts them to new needs and technology trends.

PHP and Python are both high-level programming languages that are widely used in web development, data processing and automation tasks. 1.PHP is often used to build dynamic websites and content management systems, while Python is often used to build web frameworks and data science. 2.PHP uses echo to output content, Python uses print. 3. Both support object-oriented programming, but the syntax and keywords are different. 4. PHP supports weak type conversion, while Python is more stringent. 5. PHP performance optimization includes using OPcache and asynchronous programming, while Python uses cProfile and asynchronous programming.

PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.

PHP originated in 1994 and was developed by RasmusLerdorf. It was originally used to track website visitors and gradually evolved into a server-side scripting language and was widely used in web development. Python was developed by Guidovan Rossum in the late 1980s and was first released in 1991. It emphasizes code readability and simplicity, and is suitable for scientific computing, data analysis and other fields.

PHP is suitable for web development and rapid prototyping, and Python is suitable for data science and machine learning. 1.PHP is used for dynamic web development, with simple syntax and suitable for rapid development. 2. Python has concise syntax, is suitable for multiple fields, and has a strong library ecosystem.

PHP remains important in the modernization process because it supports a large number of websites and applications and adapts to development needs through frameworks. 1.PHP7 improves performance and introduces new features. 2. Modern frameworks such as Laravel, Symfony and CodeIgniter simplify development and improve code quality. 3. Performance optimization and best practices further improve application efficiency.

PHPhassignificantlyimpactedwebdevelopmentandextendsbeyondit.1)ItpowersmajorplatformslikeWordPressandexcelsindatabaseinteractions.2)PHP'sadaptabilityallowsittoscaleforlargeapplicationsusingframeworkslikeLaravel.3)Beyondweb,PHPisusedincommand-linescrip

PHP type prompts to improve code quality and readability. 1) Scalar type tips: Since PHP7.0, basic data types are allowed to be specified in function parameters, such as int, float, etc. 2) Return type prompt: Ensure the consistency of the function return value type. 3) Union type prompt: Since PHP8.0, multiple types are allowed to be specified in function parameters or return values. 4) Nullable type prompt: Allows to include null values and handle functions that may return null values.


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

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

Hot Article

Hot Tools

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

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.

SublimeText3 Chinese version
Chinese version, very easy to use

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