xxxxxxxxxx
// Example: $set
// Update a document by setting a new field or updating an existing field.
db.users.updateOne({ name: 'Alice' }, { $set: { age: 29, location: 'New York' } });
// Example: $addToSet
// Add unique elements to an array field.
db.users.updateOne({ name: 'Bob' }, { $addToSet: { skills: 'MongoDB' } });
// Example: $push
// Add elements to an array field.
db.users.updateOne({ name: 'Charlie' }, { $push: { skills: 'Node.js' } });
// Example: $each with $push
// Add multiple elements to an array field.
db.users.updateOne({ name: 'David' }, { $push: { skills: { $each: ['React', 'Express'] } } });
// Example: $each with $addToSet
// Add multiple unique elements to an array field.
db.users.updateOne({ name: 'Eva' }, { $addToSet: { skills: { $each: ['Python', 'Java'] } } });