Mysql > remove mongodb update array; mysql > remove mongodb Update array; mysql > remove mongodb update array; Mongodb Remove API operations are divided into remove, deleteOne, and deleteMany.
1. remove
Description: Delete documents from the collection.
Grammar:
db.collection.remove(
.
{
justOne: ,
writeConcern: ,
collation:
}
)
Parameter explanation:
Query: Use the query operator to specify the delete condition. To delete all documents in the collection, pass an empty document ({}).
JustOne: Optional. To delete only one document, set it to true. Omit use the default value false and delete all documents that match the deletion criteria.
WriteConcern: Optional. Documents expressing writing concerns. Ignore using the default write concerns. If running in a transaction, do not explicitly set the write concern for the operation. To use write Concern for transactions,.
Collation: Optional. Specifies the collation to use for the operation.
Collation allows the user to specify language-specific rules for string comparisons, such as rules for letter case and accent symbols.
Sort options have the following syntax:
1.1. The sample
db.articles.remove({“views”:{$gt:4}},true)
db.articles.remove({})
2. deleteOne
Description:
Removes a single document from the collection.
Grammar:
db.collection.deleteOne(
.
{
writeConcern: ,
collation: ,
Hint: // available in MongoDB 4.4
}
)
Parameter explanation:
Filter: Use the query operator to specify the deletion criteria. Specify an empty document {} to delete the first document returned from the collection.
WriteConcern: Optional. Documents expressing writing concerns. Ignore using the default write concerns. If running in a transaction, do not explicitly set the write concern for the operation. To use write Concern for transactions,
Collation: Optional. Specifies the collation to use for the operation. Collation allows the user to specify language-specific rules for string comparisons, such as rules for letter case and accent symbols.
Hint: optional. Specifies the collation to use for the operation. Collation allows the user to specify language-specific rules for string comparisons, such as rules for letter case and accent symbols. Specifies the document or string used to support the index of the query predicate.
2.1. The sample
db.orders.deleteOne( { “_id” : ObjectId(“563237a41a4d68582c2509da”) } );
3. db.collection.deleteMany()
Description:
Deletes all documents from the collection that match the filter.
Grammar:
db.collection.deleteMany(
.
{
writeConcern: ,
collation:
}
)
Parameter explanation:
Filter: Use the query operator to specify the deletion criteria. Specify an empty document {} to delete the first document returned from the collection.
WriteConcern: Optional. Documents expressing writing concerns. Ignore using the default write concerns. If running in a transaction, do not explicitly set the write concern for the operation. To use write Concern for transactions,
Collation: Optional. Specifies the collation to use for the operation. Collation allows the user to specify language-specific rules for string comparisons, such as rules for letter case and accent symbols.
Hint: optional. Specifies the collation to use for the operation. Collation allows the user to specify language-specific rules for string comparisons, such as rules for letter case and accent symbols. A document or string that specifies the index used to support query predicates, new in version 4.4.
3.1. The sample
Db. Students. DeleteMany ({” _id “: {$in: [1, 2]}})
4. Tip: Extract the time stamp in ObjectId
ObjectId(“5fe3082595b782487444fa0f”).getTimestamp()
Return result:
ISODate(“2020-12-23T09:04:37Z”)
Next, mongodb query operations