我想知道如何在Ballerina(link)的MongoDB模块中使用update
函数来完全在MongoDB中更新/替换多个文档。
我在员工集合中有以下文件。
{ "uid" : "1", "Name" : "Peter", "Team" : "A" }
{ "uid" : "2", "Name" : "Anne", "Team" : "B" }
{ "uid" : "3", "Name" : "John", "Team" : "C" }
{ "uid" : "4", "Name" : "Mary", "Team" : "D" }
我要更新以下文件。
{ "uid" : "1", "Name" : "Peter Pan", "Team" : "A" }
{ "uid" : "2", "Name" : "Anne marie", "Team" : "A" }
{ "uid" : "3", "Name" : "John Cena", "Team" : "D" }
{ "uid" : "4", "Name" : "Mary Austin", "Team" : "D" }
答案 0 :(得分:1)
请参考以下示例。
json filter = { "age": "28" };
json document = { "$set": { "age": "27" } };
var result = conn->update("students", filter, document, true, false);
match result {
int i => io:println("updated count: " + i);
error e => io:println("update failed: " + e.message);
}
有关更多信息,请参考this。