1024programmer Java MongoDB (3) Add, delete, modify and query

MongoDB (3) Add, delete, modify and query

MongoDB is a non-relational database, and there is a big difference between the addition, deletion, modification and query of traditional databases. Here is just an outline of the knowledge points. When it is actually used, we can Baidu for detailed usage. Can. Let’s look at the major aspects first: 1. I won’t go into too much detail about the insertion and deletion inside. Relatively speaking, there are relatively few knowledge points. Let’s take a look at the updates first,

As a non-relational database, MongoDB is very different from the addition, deletion, modification and search of traditional databases. Here is just an outline of the knowledge points. When it is actually used, we can search the detailed usage on Baidu. Let’s look at the major aspects first:

First, I won’t go into too much detail about the insertion and deletion. There are relatively few knowledge points. Let’s take a look at the updates first. Common operations are still very useful and we need to use them flexibly according to the actual situation. Here are just some knowledge points. Baidu needs examples to learn how to use them:

2. The same is true for queries. Take a look at the summary of knowledge points. In fact, there are several practical ones, which are regular and easier to record:

vcD48cD48aW1nIHNyYz0=”http://www.2cto.com/ uploadfile/Collfiles/20141117/2014111709271863.png” alt=”\” />

3. Take a look Fixed collection Capped Collection: As the name suggests, it is a collection with a fixed size. Its advantage is that it has excellent performance. It performs age-out processing based on LRU (Least Recently Used) rules and insertion order. Since the collection space size is fixed, When the space is used up, the newly added objects will replace the oldest objects in the collection and always keep the latest objects.

Features: Insertion into fixed collections is extremely fast; query output speed according to insertion order Extremely fast; the oldest data can be eliminated when inserting the latest data.

Usage: It is most suitable for storing log information; caching a small number of documents…

Create: db.createCollection (“my_collection”,{capped:true,size:100000})

Convert a normal collection to a fixed collection: db.runCommand({convertTocapped:”test”,size:100000})

4. Large file collection (GridFS):

GridFS is a mechanism for storing large binary files in MongoDB, such as: storage Huge files, such as videos, high-definition pictures, etc.; GridFS will directly utilize the established replication or sharding mechanism, making fault recovery and expansion easy; it can avoid problems with the file system of user-uploaded content; it will not generate disk fragmentation.

GridFS uses two tables to store data. By default, fs.files: contains metadata objects, and fs.chunks contains binary chunks of file-related information. By using mongofiles in the bin directory, there are three commands: put (storage), get (get) and list (list). Very simple.

Okay, let’s briefly talk about MongoDB’s addition, deletion, and modification query. The specific operation examples are not given. How long does it take to check? That’s it, we need to know these things. Fixed collections and large file collections are very good ideas and deserve our special attention. Suddenly I remembered the previous series of thoughts about looking at pictures, and it seems that the same can be said here. Just look at these pictures and talk about them all. That’s pretty much it.

This article is from the internet and does not represent1024programmerPosition, please indicate the source when reprinting:https://www.1024programmer.com/mongodb-3-add-delete-modify-and-query-2/

author: admin

Previous article
Next article

Leave a Reply

Your email address will not be published. Required fields are marked *

Contact Us

Contact us

181-3619-1160

Online consultation: QQ交谈

E-mail: [email protected]

Working hours: Monday to Friday, 9:00-17:30, holidays off

Follow wechat
Scan wechat and follow us

Scan wechat and follow us

Follow Weibo
Back to top
首页
微信
电话
搜索