MongoDB is a cross-platform, document-oriented database that delivers high performance, high availability, and ease of scaling. MongoDB is a concept that works on collections and documents.
A document is a set of key-value pairs. The document has dynamic mode. Dynamic mode means that a file in the same collection does not have to have a document field or structure with the same set of collections, and that the same fields can hold different types of data.
Db. Collection name. Remove ({query}, Justone)
Query: Filter conditions, optional
Justone: Delete Only the first data that is queried, the value is true or 1 o'clock, only one data is deleted, the default is false, optional.
Prepare the data: Turn the age of _id 1 and 2 into 28
> db.student.update ({_id:1},{$set: {age:28}})
Writeresult ({"nmatched": 1, "nupserted": 0, "nmodified": 1})
> db.student.update ({_id:2},{$set: {age:28}})
Writeresult ({"nmatched": 1, "nupserted": 0, "nmodified": 1})
> Db.student.find ()
{"_id": 1, "name": "Zhangsan", "Age": 28}
{"_id": 2, "name": "Lisi", "Age": 28}
{"_id": 3, "name": "Wangwu", "Age": 30}
{"_id": 4, "name": "Zhaoliu", "Age": 28}
{"_id": 5, "name": "Qianliu", "Age": 33}
{"_id": 6, "name": "Sunba", "Age": 32}
{"_id": 7, "name": "Songjiu", "Skill": ["MongoDB", "Java"]}
1. Use two parameters:
Delete the first piece of data from age=28
> Db.student.remove ({age:28}, True)
Writeresult ({"nremoved": 1})
> Db.student.find ()
{"_id": 2, "n Ame ": Lisi", "age":
{"_id": 3, "name": "Wangwu", "age":
{"_id": 4, "name": "Zhaoliu", "Age":
{"_id": 5, "name": "Qianliu", "Age":
32} {"_id": 6, "name": "Sunba", "Age"
2. Use one parameter:
Delete all data from age=28
> Db.student.remove ({age:28})
Writeresult ({"Nremoved": 2})
> Db.student.find ()
{"_id": 3, " Name ': ' Wangwu ', ' age ':
{' _id ': 5, ' name ': ' Qianliu ', ' age ': +}
{' _id ': 6, ' name ': ' Sunba ', ' age ": 32}
3, delete all the data of the collection, "{}" in parentheses must have, to indicate an empty filter condition:
In addition, when the Remove () method is used to delete the data, the table will still exist. Using the Drop () method deletes the table, and the drop () is more efficient than remove ().