MongoDB Modify, delete a document's Domain property instance
In the development of the website, perhaps the initial design unreasonable, or late business changes, will cause the document structure will have some useless attributes, need to remove or modify, because MongoDB is no Schema, unlike the relational database column properties defined in the table rather than the record, MongoDB Each document in the collection can have its own different domain properties. MongoDB uses db.collections.update to modify the domain properties of several documents in the collection, use $set to increase the domain, $unset delete the domain.
Delete a field for all documents in the collection
Db.posts.update ({}, {$unset: {deleted_at:1}}, {multi:true})
1. The first parameter indicates that some documents are selected, where {} indicates that all documents in the current posts collection are selected
2. The second parameter is a specific update operation, $unset means to delete the domain
3. The third parameter is an additional option, {Multi:true} means that all documents that meet the requirements are updated, and the first one is updated by default
You can also delete multiple domains at the same time
Db.categories.update ({}, {$unset: {deleted_at:1, desc:1}}, {multi:true})
also delete and add domains at the same time
Db.tags.update ( {}, {$unset: {deleted_at:1}, $set: {slug:1, Description:1}}, {multi:true})
This article refers to: http://www.lai18.com/content/348300.html, off-topic: there are a lot of people are not optimistic about MongoDB, and even listed MongoDB many problems, in fact, MongoDB is just a tool, What we need is that it can help us to solve the demand, believing that MongoDB will be getting better.
Read "MongoDB Technical Knowledge" series of technical Articles to organize the collection
1Basics to get started with MongoDB
2MongoDB Getting Started Tutorials (includes installation, common commands, related concepts, tips, common actions, etc.)
3MongoDB Getting Started Tutorial Shard Technology detailed
4MongoDB Introductory tutorials Common operations and Maintenance technology introduction
Example of C # driver operation in 5MongoDB Starter Tutorial
6MongoDB Introductory Tutorial Master-slave replication configuration detailed
Introduction to the aggregation and cursor operations of the 7MongoDB Getting Started tutorial
8MongoDB Getting Started teaching the operation of adding and deleting MongoDB database
An analysis of index operation of 9MongoDB Getting Started tutorial
10MongoDB Getting Started tutorial of the MongoDB database installation diagram under Windows
11MongoDB query field does not create an index caused by Connection Timeout exception solution case sharing
12MongoDB log file is too large a workaround
13MongoDB Community Edition and Enterprise Edition difference comparison table
14MongoDB Chinese Community Initiator takes you to learn MongoDB.
Analysis on performance bottleneck of 15 MongoDB database
The method and performance of 16MongoDB paging query
Cluster architecture implementation of 17MongoDB Shard storage
18Mongodb Bulk deletion of Gridfs file instances
19Mongodb adding, removing Shard server instances
20Mongodb adding, removing Arbiter node instances
MongoDB Installation and configuration tutorial under 21CentOS system
22MongoDB Modifying and deleting a document's Domain property instance
MongoDB basic operations in 23Python: connecting, querying instances
24MongoDB Export Query Results to file example
Things to keep in mind when creating indexes in 25MongoDB
Some pits in 26MongoDB (best not to use)
27 adding user rights to MongoDB sharing method
Simple installation and basic operation of MongoDB under 28Linux system
Basic management commands for the 29MongoDB tutorial
Aggregation of 30MongoDB Tutorials (count, distinct, and group)
Introduction to the index of 31MongoDB tutorials
Data manipulation examples of 32MongoDB tutorials
Basics of getting Started with 33MongoDB tutorials
Examples of query operations for 34MongoDB tutorials
35MongoDB Series Tutorial (iv): Set User access rights
36MongoDB Series Tutorial (eight): Gridfs storage
Introduction to features and advantages of 37MongoDB database
38MongoDB about MongoDB Five features
39MongoDB Series Tutorial (vi): Java operation MongoDB Instance
40MongoDB Series Tutorial (vii): A detailed description of the MONGODB data structure
41MongoDB Series Tutorial (v): MONGO Grammar and MySQL syntax comparison learning
42MongoDB Series Tutorial (ii): About MongoDB
43MongoDB Series Tutorial (i): NoSQL origins
Introduction to MapReduce in 44MongoDB
45MongoDB Series Tutorial (iii): Download and install MongoDB in Windows
46 on how to back up MongoDB
47MongoDB Common Command Summary
48MongoDB and MySQL operation comparison table and the difference introduction
49MongoDB Security Configuration Detailed
Bson Introduction and usage examples in 50MongoDB
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
MongoDB Modify, delete a document's Domain property instance