gpt4 book ai didi

json - 如何删除mongodb中的多个文件?

转载 作者:可可西里 更新时间:2023-11-01 10:00:12 24 4
gpt4 key购买 nike

我有名为 users 的集合名称。在这个集合中,共有 6 个文档。我想使用名为“名称”的列名称之一删除 3 个文档。我使用了这个查询:

db.users.deleteMany([
{
"name":"viki"
},
{
"name" : "vino"
},
{
"name" : "naranyamoorthy"
}
])

但是我遇到了一个错误,谁能帮帮我?

这些是我的文件。我想删除 3 个名为 viki、vino、naranyamoorthy 的文件。

 { "_id" : ObjectId("58934f10c7592b1494fd9a4d"), "name" : "viki", "age" : 100, "subject" : [ "c", "node.js", "java" ], "address" : { "city" : "chennai", "state" : "tamilnadu", "pincode" : "123", "district" : [ "thambaram" ] } }
{ "_id" : ObjectId("58934f57e8796616482b48d1"), "name" : "vino", "age" : 21, "subject" : [ "Bootstrap", "j2ee", "java", null, "node" ], "address" : { "city" : "Antartica", "state" : "USA", "pincode" : "456", "country" : "USA", "core" : [ "alliswell" ] } }
{ "_id" : ObjectId("58934f8d09a2cb0d0c6f6af5"), "name" : "ranjith", "age" : 12, "subject" : [ "c++", "php", "java" ], "address" : { "city" : "japan", "state" : "UK", "pincode" : "45685" }, "subject[2]" : "php" }
{ "_id" : ObjectId("58955fd44b2ba9078463d2a7"), "name" : "waseem", "age" : 200, "subject" : [ "c++", "c", "Analysis" ], "address" : { "city" : "Dubai", "state" : "UAE", "pincode" : "5820", "country" : [ "USA" ] } }
{ "_id" : ObjectId("589561109b03d692c45114ef"), "name" : "sunadarpichai", "age" : 22, "subject" : [ "c", "node.js", "c++", "Android programming" ], "address" : { "city" : "losAngeles", "state" : "USA", "pincode" : "12341", "district" : "thambaram" } }
{ "_id" : ObjectId("58956389362992d7976510d4"), "name" : "naranyamoorthy", "age" : 21, "subject" : [ "Bootstrap", "node.js", "j2ee", "javascript" ], "address" : { "city" : "Afganistan", "state" : "tamilnadu", "pincode" : "9597653749", "country" : "USA", "core" : [ "alliswell" ] } }

最佳答案

您需要将单个查询对象传递给与要删除的文档相匹配的 deleteMany。在这种情况下,您可以使用 $in:

db.users.deleteMany({name: {$in: ["viki", "vino", "naranyamoorthy"]}})

关于json - 如何删除mongodb中的多个文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43788762/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com