Maintenance in progress: we are indexing a large batch of new skills. Some pages may load slowly or briefly show no results. Nothing is lost, and everything is back to normal within the hour.

Mongodb

Administer MongoDB databases. Configure replica sets, sharding, and backups. Use when managing MongoDB deployments.

majiayu000 aaa0597 2 files · 2.1 KB Updated 567 repo stars

File contents

MongoDB

Administer MongoDB NoSQL databases.

Installation & Setup

# Install
apt install mongodb-org

# Start service
systemctl start mongod

# Connect
mongosh

# Create user
use admin
db.createUser({
  user: "admin",
  pwd: "secret",
  roles: ["root"]
})

Basic Operations

// Create database and collection
use mydb
db.users.insertOne({ name: "John", email: "john@example.com" })

// Query
db.users.find({ name: "John" })
db.users.find().sort({ name: 1 }).limit(10)

// Index
db.users.createIndex({ email: 1 }, { unique: true })

Replica Set

// Initialize replica set
rs.initiate({
  _id: "myReplicaSet",
  members: [
    { _id: 0, host: "mongo1:27017" },
    { _id: 1, host: "mongo2:27017" },
    { _id: 2, host: "mongo3:27017" }
  ]
})

Backup

# Backup
mongodump --out /backup/

# Restore
mongorestore /backup/

Best Practices

  • Use replica sets in production
  • Implement proper indexing
  • Enable authentication
  • Regular backups with mongodump

majiayu000/claude-skill-registry-data/tree/main/data/mongodb-bagelhole-devops-security-agen commit aaa05973fc

Frequently asked questions

npx skillmds add majiayu000/mongodb-3