MongoDB modifies and deletes the domain attribute instance of a document.
MongoDB modifies or deletes a file's domain attribute instance
During website development, the initial design may be unreasonable or the business changes in the future may cause some useless attributes in the document structure and need to be deleted or modified, because MongoDB has no Schema, column attributes are defined in tables rather than records, unlike relational databases, each document in the MongoDB set can have different domain attributes. In MongoDB, use db. collections. update to modify the domain attributes of several documents in the collection, add a domain using $ set, and delete a domain using $ unset.
Deletes a domain of all documents in a collection.
db.posts.update({}, { $unset: { deleted_at: 1 } }, { multi: true })
1. The first parameter indicates that some documents are selected. Here {} indicates that all documents in the current posts set are selected.
2. The second parameter is the specific update operation. $ unset indicates that the domain is deleted.
3. The third parameter is an additional option. {multi: true} indicates that all documents meeting the requirements are updated. By default, only the first document is updated.
You can also delete multiple domains at the same time.
db.categories.update({}, { $unset: { deleted_at: 1, desc: 1 } }, { multi: true })
It also deletes and adds a domain at the same time.
db.tags.update( {}, { $unset: { deleted_at: 1 }, $set: { slug: 1, description: 1 } }, { multi: true })
This article reference: http://www.lai18.com/content/348300.html, off the topic: There are a lot of people are not optimistic about MongoDB, and even list A Lot Of MongoDB problems, in fact, MongoDB is just a tool, what we need is that it can help us solve our needs. I believe MongoDB will get better and better.
Read the MongoDB technical knowledge series and add them to favorites.
1 basic knowledge for getting started with MongoDB
2MongoDB getting started tutorial (including installation, Common commands, related concepts, usage skills, and Common Operations)
3 MongoDB getting started
Introduction to common O & M technologies in the 4MongoDB getting started tutorial
C # driver operation instance in 5MongoDB getting started tutorial
Step 6 MongoDB master-slave replication Configuration
Introduction to aggregation and cursor operations in the 7MongoDB getting started tutorial
An Introduction to MongoDB database addition, deletion, query, modification, and so on
9 MongoDB getting started tutorial-index Operation Analysis
10MongoDB getting started tutorial-MongoDB database installation diagram in Windows
11MongoDB connection timeout caused by no index created in the query field case study
12. Solution to excessive MongoDB log files
Differences between Community edition and Enterprise Edition of 13MongoDB
14 mongoDB Chinese community sponsors will show you how to learn mongoDB
15 Analysis on MongoDB database performance bottlenecks
16 MongoDB paging query methods and Performance
Cluster architecture Implementation of 17MongoDB shard Storage
18Mongodb batch Delete gridfs file instances
19Mongodb add and remove Shard Server instances
Add and remove Arbiter node instances in apsaradb for MongoDB
Tutorial on installing and configuring MongoDB in 21CentOS
22MongoDB modifies or deletes a file's domain attribute instance
MongoDB basic operations in 23Python: connecting to and querying instances
Example of exporting query results to files in 24MongoDB
Notes for creating indexes in MongoDB
Some pitfalls in 26MongoDB (not recommended)
27. Add a user permission to MongoDB
Simple installation and basic operations of MongoDB in 28Linux
Basic management commands for the 29MongoDB tutorial
Aggregation of 30MongoDB tutorial (count, distinct, and group)
Index introduction in 31 MongoDB tutorial
Data operation instance in the 32MongoDB tutorial
33MongoDB Basics
Query operation instances in the 34MongoDB tutorial
35 MongoDB series tutorial (4): Set User Access Permissions
36MongoDB series tutorial (8): GridFS storage details
37MongoDB features and advantages
38MongoDB introduction five features
39MongoDB series tutorial (6): java operations on mongodb instances
40MongoDB series tutorial (7): Detailed description of MongoDb Data Structure
41MongoDB series tutorial (5): Comparison of mongo syntax and mysql syntax
42MongoDB series tutorial (II): MongoDB Introduction
43MongoDB series tutorial (1): NoSQL Origin
Introduction to MapReduce in 44MongoDB
45 MongoDB series tutorial (3): download and install MongoDB in Windows
46. MongoDB backup methods
47 summary of common MongoDB commands
48MongoDB and MySQL operations comparison table and differences
49MongoDB security configuration details
Introduction and use of bson in 50MongoDB
Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.