Mongodb 如何在mongo驱动程序中更新指定数量的文档,就像mysql`update table set Field=dxx limit 50一样`

Mongodb 如何在mongo驱动程序中更新指定数量的文档,就像mysql`update table set Field=dxx limit 50一样`,mongodb,go,Mongodb,Go,如何像mysql一样在Mongo中更新指定数量的文档 update table set filed = dxx limit 50 使用这个go版本的mongo驱动程序 使用Mongo DB Shell,我们可以使用以下查询: db.collection.find() 函数(元素){ element.newField=newData; db.collection.save(元素); }); 要使用mongo go驱动程序实现相同的功能, 1.使用Collection.find()方法在find

如何像mysql一样在Mongo中更新指定数量的文档

update table set filed = dxx limit 50
使用这个go版本的mongo驱动程序
使用Mongo DB Shell,我们可以使用以下查询:
db.collection.find()
函数(元素){
element.newField=newData;
db.collection.save(元素);
});

要使用mongo go驱动程序实现相同的功能,

1.使用Collection.find()方法在find options中使用limit获取所需记录
2.使用find query的光标,并在[]mongo.WriteModel中追加所需的更新查询
3.以[]mongo.WriteModel切片作为输入执行collection.BulkWrite()方法,并使用返回的BulkWriteResult


到目前为止,您尝试了什么?mongodb驱动程序地址是什么?我是限制这个驱动程序这是获取然后更新,这是1+n数字命令吗?mongo不像mysql one命令那样执行它?是的,这是针对您在查询中提到的同一个mongo go驱动程序,它通过go程序连接到mongo shell并执行查询。使用mongo go驱动程序,上次检查时,每个方法都有一个for-each和find不可用。可能您可以在mongo go门户中创建jira票证,他们将在进一步更新中介绍此功能。