const mg = require('mongoose');
const uri = 'mongodb://zhiyin:zhiyin123@192.168.136.130:27017/zhiyin?authSource=zhiyin';
mg.connect(uri).then(async () => {
  const r = await mg.connection.db.collection('users').updateMany(
    {},
    { $set: { role: 'admin' } }
  );
  console.log('Updated:', r.modifiedCount + r.upsertedCount);
  const users = await mg.connection.db.collection('users').find().project({ _id: 1, phone: 1, role: 1 }).toArray();
  console.log(JSON.stringify(users.map(u => ({ id: u._id.toString(), phone: u.phone, role: u.role }))));
  await mg.disconnect();
}).catch(e => console.error(e.message));