Sign inSign up

toolkitbox/mongo

By toolkitbox

•Updated 17 days ago

DevOps toolkit - mongo client

Image
0

1.7K

toolkitbox/mongo repository overview

⁠MongoDB Client (mongosh)

GitHub Stars GitHub Issues Docker Pulls

📢 Found an issue or want to request a new tool? Open an issue on GitHub⁠

Modern MongoDB shell for interacting with MongoDB databases.

⁠Quick Start

⁠Docker
# Interactive mode
docker run -it --rm \
  ghcr.io/pabpereza/toolkitbox/mongo:latest \
  mongosh "mongodb://my-server:27017"

# With authentication
docker run -it --rm \
  ghcr.io/pabpereza/toolkitbox/mongo:latest \
  mongosh "mongodb://user:password@my-server:27017/database"

# Run single command
docker run --rm \
  ghcr.io/pabpereza/toolkitbox/mongo:latest \
  mongosh "mongodb://my-server:27017" --eval "db.getCollectionNames()"
⁠Kubernetes
apiVersion: v1
kind: Pod
metadata:
  name: mongo-client
spec:
  containers:
  - name: mongo-client
    image: ghcr.io/pabpereza/toolkitbox/mongo:latest
    command: ["sleep", "infinity"]
    env:
    - name: MONGODB_URI
      valueFrom:
        secretKeyRef:
          name: mongo-credentials
          key: uri

⁠Description

mongosh is the official MongoDB shell that replaces the legacy mongo shell. It provides a rich command line interface with autocomplete, syntax highlighting, and full JavaScript support.

⁠Installation

This component downloads and installs mongosh directly from the official MongoDB binaries. Supports x64 and arm64 architectures.

⁠Basic Usage

⁠Connect to local MongoDB
mongosh
⁠Connect to remote server
mongosh "mongodb://hostname:27017"
⁠Connect with authentication
mongosh "mongodb://user:password@hostname:27017/database"
⁠Connect to MongoDB Atlas
mongosh "mongodb+srv://cluster.mongodb.net/mydb" --username user
⁠Execute command and exit
mongosh --eval "db.getCollectionNames()"
⁠Execute JavaScript script
mongosh script.js

⁠Useful Shell Commands

// Show databases
show dbs

// Use database
use my_database

// Show collections
show collections

// Find documents
db.my_collection.find()

// Insert document
db.my_collection.insertOne({ name: "example" })

// Find with filter
db.my_collection.find({ field: "value" })

// Count documents
db.my_collection.countDocuments()

// Create index
db.my_collection.createIndex({ field: 1 })

⁠Connection Options

OptionDescription
--hostMongoDB server
--portPort (default: 27017)
--usernameAuthentication user
--passwordPassword
--authenticationDatabaseAuthentication database
--evalExecute JavaScript expression

⁠Available Legacy Versions

  • v3.6 - MongoDB 3.6 (uses classic mongo shell)
  • v4.4 - MongoDB 4.4 (uses classic mongo shell)

⁠Official Documentation

Tag summary

Content type

Image

Digest

sha256:0a204209d…

Size

53.1 MB

Last updated

17 days ago

docker pull toolkitbox/mongo