根据筛选条件 删除部分数据
> db.winner.
find
()db.winner.
find
()
{
"_id"
: ObjectId(
"592c2e01c070fc0df2f50f09"
),
"x"
: 0 }
{
"_id"
: ObjectId(
"592c2e01c070fc0df2f50f0b"
),
"x"
: 2 }
{
"_id"
: ObjectId(
"592c2e01c070fc0df2f50f0c"
),
"x"
: 3 }
{
"_id"
: ObjectId(
"592c2e01c070fc0df2f50f0d"
),
"x"
: 4 }
{
"_id"
: ObjectId(
"592c2e01c070fc0df2f50f0e"
),
"x"
: 5 }
{
"_id"
: ObjectId(
"592c2e01c070fc0df2f50f0f"
),
"x"
: 6 }
{
"_id"
: ObjectId(
"592c2e01c070fc0df2f50f10"
),
"x"
: 7 }
{
"_id"
: ObjectId(
"592c2e01c070fc0df2f50f11"
),
"x"
: 8 }
{
"_id"
: ObjectId(
"592c2e01c070fc0df2f50f12"
),
"x"
: 9 }
{
"_id"
: ObjectId(
"592c2e01c070fc0df2f50f13"
),
"x"
: 10 }
{
"_id"
: ObjectId(
"592c2e01c070fc0df2f50f14"
),
"x"
: 11 }
{
"_id"
: ObjectId(
"592c2e01c070fc0df2f50f15"
),
"x"
: 12 }
{
"_id"
: ObjectId(
"592c2e01c070fc0df2f50f16"
),
"x"
: 13 }
{
"_id"
: ObjectId(
"592c2e01c070fc0df2f50f17"
),
"x"
: 14 }
{
"_id"
: ObjectId(
"592c2e01c070fc0df2f50f18"
),
"x"
: 15 }
{
"_id"
: ObjectId(
"592c2e01c070fc0df2f50f19"
),
"x"
: 16 }
{
"_id"
: ObjectId(
"592c2e01c070fc0df2f50f1a"
),
"x"
: 17 }
{
"_id"
: ObjectId(
"592c2e01c070fc0df2f50f1b"
),
"x"
: 18 }
{
"_id"
: ObjectId(
"592c2e01c070fc0df2f50f1c"
),
"x"
: 19 }
{
"_id"
: ObjectId(
"592c2e01c070fc0df2f50f1d"
),
"x"
: 20 }
Type
"it"
for
more
> db.winnerdb.winne.remove({x:20})
> db.winedb.winne.
find
({x:20})
删除全部
db.winner.remove()
db.winner.
find
()
show tables;
system.indexes
win_collection
winer
winner
由于MongoDB里面的集合不像MySQL里面的表还有结构什么的,所以当我们删除所有数据时,可以直接
删除整个集合,当下次插入数据时,又会创建一个新的集合。
db.winner.drop()
>
for
(i=0;i<100;i++)db.winner.insert({x:i})
for
(i=0;i<100;i++)db.winner.insert({x:i})
> db.winner.
find
()db.winner.
find
()
{
"_id"
: ObjectId(
"592c34bd17c668d64f637dab"
),
"x"
: 25 }
{
"_id"
: ObjectId(
"592c34bd17c668d64f637dac"
),
"x"
: 26 }
{
"_id"
: ObjectId(
"592c34bd17c668d64f637dad"
),
"x"
: 27 }
{
"_id"
: ObjectId(
"592c34bd17c668d64f637dae"
),
"x"
: 28 }
{
"_id"
: ObjectId(
"592c34bd17c668d64f637daf"
),
"x"
: 29 }
{
"_id"
: ObjectId(
"592c34bd17c668d64f637db0"
),
"x"
: 30 }
{
"_id"
: ObjectId(
"592c34bd17c668d64f637db1"
),
"x"
: 31 }
> db.winner.drop()
true
> db.winner.
find
()
> show tables;
system.indexes
win_collection
winer
经过对比,已经删除了之前的集合,但是这样的删除不会影响我们后面插入数据。