In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
preface
MongoDB and MySQL basic statements are still very different, today I will introduce some of the commonly used basic statements of MongoDB, the following words do not say much, let's take a look at the detailed introduction
MONgoDB delete statement
delete() Delete
Delete a collection
db.collection.deleteOne()
Delete multiple collections
db.collection.deletMany();
remove() Delete
Delete all name: Li Si's data
db.student.remove({name:"Li Si"});
Delete only one sex: male data delete only one
db.student.remove({sex:"male"},true);
delete all
db.student.remove({});
false deletion of database
Sometimes when the user deletes the operation, the requirement is that only the data is hidden, not really deleted from the database.
At this time, fake deletion was used. For example, this is Zhang Sanfa's two Weibo posts:
db.student.insert([ {name:"Zhang San",content:"Good mood today",isDel:0}, {name:"Zhang San",content:"Average mood today",isDel:0},]);
The user adds two pieces of data, but only keeps the latter one. Delete the former one. In this case, use false deletion. Add a field isDel:0 when adding data.
So when the user deletes data, it executes not the remove method, but the update method.
db.student.update({"_id" : ObjectId("5bd6a46f1eb7a22fa07cb382")},{ $set:{ isDel:1 }});
When isDel:0 is indicating that the user has not deleted, 1 is indicating that the user has deleted.
Therefore, when querying, you need to filter the name and isDel conditions
db.student.find({name:"Zhang San",isDel:0});
Query the data that the user has not deleted:
Then you can fake deletion.
Operation and modification of batch data
Insert 10000 documents into the collection
var arr= [];for(var i=0;i
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.