> db.things.find()
{ "_id" : ObjectId("561d640e7ce0a090519b3a0d"), "f" : 7, "d" : 4, "e" : 5 }
{ "_id" : ObjectId("561d64127ce0a090519b3a0e"), "d" : 4, "e" : 5 }
{ "_id" : ObjectId("561d643c7ce0a090519b3a0f"), "x" : 0 }
{ "_id" : ObjectId("561d643c7ce0a090519b3a10"), "x" : 1 }
{ "_id" : ObjectId("561d643c7ce0a090519b3a11"), "x" : 2 }
{ "_id" : ObjectId("561d643c7ce0a090519b3a12"), "x" : 3 }
{ "_id" : ObjectId("561d643c7ce0a090519b3a13"), "x" : 4 }
{ "_id" : ObjectId("561d643c7ce0a090519b3a14"), "x" : 5 }
{ "_id" : ObjectId("561d643c7ce0a090519b3a15"), "x" : 6 }
{ "_id" : ObjectId("561d643c7ce0a090519b3a16"), "x" : 7 }
{ "_id" : ObjectId("561d643c7ce0a090519b3a17"), "x" : 8 }
{ "_id" : ObjectId("561d643c7ce0a090519b3a18"), "x" : 9 }
文档列出了使用以下语法删除单个项目的命令:
> db.things.remove({ "x" : 0 })
这将删除第三个列出的对象。
我想知道的是,是否有一个命令用于删除所有对象的" x"在上面的代码中?
答案 0 :(得分:2)
你可以使用$ exists
db.things.remove({ x: { $exists: true } });
http://docs.mongodb.org/manual/reference/operator/query/exists/