我们知道在mysql中,而不是执行3次以下查询,我们可以在1>和2>
中给出的单个执行中执行相同的操作UPDATE feedbacks SET _id = '5c6a8bcfce1454086fefb879' WHERE user_rol = '26-02-2018';
UPDATE feedbacks SET _id = '5c6a89d3ce1454086fefb877' WHERE user_rol = '26-02-2017';
UPDATE feedbacks SET _id = '5c6a896ece1454086fefb876' WHERE user_rol = '26-02-2016';
1>
INSERT INTO feedbacks (_id, added_on)
VALUES
('5c6a8bcfce1454086fefb879', '26-02-2018'),
('5c6a89d3ce1454086fefb877', '26-02-2017'),
('5c6a896ece1454086fefb876', '26-02-2016')
ON DUPLICATE KEY UPDATE added_on = VALUES(added_on)
2>
UPDATE feedbacks
SET added_on = CASE
WHEN _id = '5c6a8bcfce1454086fefb879' THEN '26-02-2018'
WHEN _id = '5c6a89d3ce1454086fefb877' THEN '26-02-2017'
WHEN _id = '5c6a896ece1454086fefb876' THEN '26-02-2016'
END
WHERE _id IN ('5c6a8bcfce1454086fefb879', '5c6a89d3ce1454086fefb877', '5c6a896ece1454086fefb876')
现在我的问题是,我们是否可以在mongodb中执行相同的操作(在一次执行中更新具有不同值的多行)?
答案 0 :(得分:0)
在具有相同条件或查询的mongo中,可以通过将'multi'标志设置为true来更新多个记录。请参考链接。 https://docs.mongodb.com/manual/reference/method/db.collection.update/
但是,条件不同,这是行不通的。
有关批量更新,您可以参考: https://docs.mongodb.com/manual/reference/method/Bulk.find.update/#Bulk.find.update