Skip to content

binrchq/mongodb-cli

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

MongoDB CLI

Go Reference Go Report Card License: MIT

A standalone, feature-rich MongoDB interactive CLI client for Go applications.

Features

  • 🚀 Full MongoDB protocol support
  • 🔧 Customizable connection parameters
  • 🔒 TLS/SSL support
  • 💾 Connection pooling
  • 📊 Pretty print JSON output
  • ⏱️ Query timing
  • 🔄 Replica set support
  • 🎯 Database and collection operations
  • 👤 Authentication with configurable auth source

Installation

go get github.com/binrchq/mongodb-cli

Quick Start

package main

import (
    "log"
    "os"
    
    mongodbcli "github.com/binrchq/mongodb-cli"
)

func main() {
    cli := mongodbcli.NewCLI(
        os.Stdin,
        "localhost",
        27017,
        "admin",
        "password",
        "mydb",
    )
    
    if err := cli.Connect(); err != nil {
        log.Fatal(err)
    }
    defer cli.Close()
    
    if err := cli.Start(); err != nil {
        log.Fatal(err)
    }
}

Advanced Configuration

config := &mongodbcli.Config{
    Host:                   "localhost",
    Port:                   27017,
    Username:               "admin",
    Password:               "password",
    Database:               "mydb",
    AuthSource:             "admin",
    ReplicaSet:             "rs0",
    ConnectTimeout:         15 * time.Second,
    ServerSelectionTimeout: 15 * time.Second,
    MaxPoolSize:            200,
    MinPoolSize:            10,
    RetryWrites:            true,
    RetryReads:             true,
    TLS:                    true,
}

cli := mongodbcli.NewCLIWithConfig(terminal, config)

Database Commands

  • show dbs - List databases
  • use <db> - Switch database
  • show collections - List collections
  • show users - List users

Collection Operations

db.users.find()
db.users.find({"age": 25})
db.users.findOne({"name": "John"})
db.users.insertOne({"name": "Alice", "age": 30})
db.users.insertMany([{...}, {...}])
db.users.deleteOne({"name": "Alice"})
db.users.deleteMany({"age": {"$gt": 50}})
db.users.count()
db.users.count({"status": "active"})

Special Commands

  • help - Show help
  • exit, quit - Exit
  • pretty - Toggle pretty print
  • timing - Toggle timing

Requirements

  • Go 1.21 or higher
  • MongoDB 4.0 or higher

Dependencies

License

MIT License - see LICENSE file for details.

Author

Maintained by binrc.

Related Projects

About

Database CLI for MONGODB

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages