| name | mongodb |
| description | Use for managing MongoDB. |
Usage
bun {base dir}/scripts/query.ts "<query>"
Examples
# Simple read
bun {base dir}/scripts/query.ts "db.collection('users').findOne()"
# Query with ObjectId
bun {base dir}/scripts/query.ts "db.collection('users').findOne({ _id: new ObjectId('...') })"
# Multi-step update (Batching)
bun {base dir}/scripts/query.ts "Promise.all([
db.collection('rewards').deleteMany({ userId: new ObjectId('...') }),
db.collection('users').updateOne({ _id: new ObjectId('...') }, { \$set: { 'dailyXp.count': 0 } })
])"
Tips
- Use query.ts over writing one-off scripts. Use
Promise.allfor parallel operations or an IIFE(async () => { ... })()for complex multi-step logic. ObjectIdis globally available in the query context.- Use
limit(1)orfindOne()to understand schema without wasting tokens. - Use
countDocuments()instead of fetching docs for existence checks.