Something like this maybe?
test [direct: primary] test> db.coll.insertMany([{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{}])
{
acknowledged: true,
insertedIds: {
'0': ObjectId("6228e4cc551b7b41d956268b"),
'1': ObjectId("6228e4cc551b7b41d956268c"),
'2': ObjectId("6228e4cc551b7b41d956268d"),
'3': ObjectId("6228e4cc551b7b41d956268e"),
'4': ObjectId("6228e4cc551b7b41d956268f"),
'5': ObjectId("6228e4cc551b7b41d9562690"),
'6': ObjectId("6228e4cc551b7b41d9562691"),
'7': ObjectId("6228e4cc551b7b41d9562692"),
'8': ObjectId("6228e4cc551b7b41d9562693"),
'9': ObjectId("6228e4cc551b7b41d9562694"),
'10': ObjectId("6228e4cc551b7b41d9562695"),
'11': ObjectId("6228e4cc551b7b41d9562696"),
'12': ObjectId("6228e4cc551b7b41d9562697"),
'13': ObjectId("6228e4cc551b7b41d9562698"),
'14': ObjectId("6228e4cc551b7b41d9562699"),
'15': ObjectId("6228e4cc551b7b41d956269a"),
'16': ObjectId("6228e4cc551b7b41d956269b"),
'17': ObjectId("6228e4cc551b7b41d956269c"),
'18': ObjectId("6228e4cc551b7b41d956269d"),
'19': ObjectId("6228e4cc551b7b41d956269e")
}
}
test [direct: primary] test> db.coll.updateMany({},[{$set: {
... fries: {$switch: {
..... branches: [
..... { case: { $lt : [ { $rand : {} }, 0.3 ] }, then: "small" },
..... { case: { $lt : [ { $rand : {} }, 0.6 ] }, then: "medium" },
..... ],
..... default: "large"
..... }}
... }
... }])
{
acknowledged: true,
insertedId: null,
matchedCount: 20,
modifiedCount: 20,
upsertedCount: 0
}
test [direct: primary] test> db.coll.find()
[
{ _id: ObjectId("6228e4cc551b7b41d956268b"), fries: 'small' },
{ _id: ObjectId("6228e4cc551b7b41d956268c"), fries: 'large' },
{ _id: ObjectId("6228e4cc551b7b41d956268d"), fries: 'small' },
{ _id: ObjectId("6228e4cc551b7b41d956268e"), fries: 'medium' },
{ _id: ObjectId("6228e4cc551b7b41d956268f"), fries: 'medium' },
{ _id: ObjectId("6228e4cc551b7b41d9562690"), fries: 'medium' },
{ _id: ObjectId("6228e4cc551b7b41d9562691"), fries: 'medium' },
{ _id: ObjectId("6228e4cc551b7b41d9562692"), fries: 'small' },
{ _id: ObjectId("6228e4cc551b7b41d9562693"), fries: 'small' },
{ _id: ObjectId("6228e4cc551b7b41d9562694"), fries: 'large' },
{ _id: ObjectId("6228e4cc551b7b41d9562695"), fries: 'medium' },
{ _id: ObjectId("6228e4cc551b7b41d9562696"), fries: 'large' },
{ _id: ObjectId("6228e4cc551b7b41d9562697"), fries: 'medium' },
{ _id: ObjectId("6228e4cc551b7b41d9562698"), fries: 'medium' },
{ _id: ObjectId("6228e4cc551b7b41d9562699"), fries: 'medium' },
{ _id: ObjectId("6228e4cc551b7b41d956269a"), fries: 'small' },
{ _id: ObjectId("6228e4cc551b7b41d956269b"), fries: 'medium' },
{ _id: ObjectId("6228e4cc551b7b41d956269c"), fries: 'medium' },
{ _id: ObjectId("6228e4cc551b7b41d956269d"), fries: 'medium' },
{ _id: ObjectId("6228e4cc551b7b41d956269e"), fries: 'large' }
]