共计 1124 个字符,预计需要花费 3 分钟才能阅读完成。
deleteOne
删除符合条件的一条数据
{
"_id" : ObjectId("5afd209e2c63ae1a943bdb20"),
"bar" : "test"
}
{
"_id" : ObjectId("5afd21502c63ae1a943bdb21"),
"a" : "b"
}
{
"_id" : ObjectId("5afd21502c63ae1a943bdb22"),
"c" : "d"
}
{
"_id" : ObjectId("5afd25062c63ae1a943bdb23"),
"bar" : "test"
}
{
"_id" : ObjectId("5afd254e2c63ae1a943bdb24"),
"bar" : "test"
}
结果
db.test.deleteOne({"bar":"test"})
{
"_id" : ObjectId("5afd21502c63ae1a943bdb21"),
"a" : "b"
}
{
"_id" : ObjectId("5afd21502c63ae1a943bdb22"),
"c" : "d"
}
{
"_id" : ObjectId("5afd25062c63ae1a943bdb23"),
"bar" : "test"
}
{
"_id" : ObjectId("5afd254e2c63ae1a943bdb24"),
"bar" : "test"
}
deleteMany
输出符合条件的多条数据
db.test.deleteMany({"bar":"test"})
{
"_id" : ObjectId("5afd21502c63ae1a943bdb21"),
"a" : "b"
}
{
"_id" : ObjectId("5afd21502c63ae1a943bdb22"),
"c" : "d"
}
remove
删除符合条件的多条数据,没发现和deleteMany之间的区别有知道的麻烦评论
原始数据
{
"_id" : ObjectId("5afd21502c63ae1a943bdb21"),
"a" : "b"
}
{
"_id" : ObjectId("5afd21502c63ae1a943bdb22"),
"c" : "d"
}
{
"_id" : ObjectId("5afd2ac32c63ae1a943bdb25"),
"a" : "b"
}
{
"_id" : ObjectId("5afd2ac32c63ae1a943bdb26"),
"c" : "d"
}
db.test.remove({"a":"b"})
{
"_id" : ObjectId("5afd21502c63ae1a943bdb22"),
"c" : "d"
}
{
"_id" : ObjectId("5afd2ac32c63ae1a943bdb26"),
"c" : "d"
}
drop
直接删除整个表数据,速度快
db.test.drop()
正文完
请博主喝杯咖啡吧!