Golang MongoDB Integration Examples

Get Program

Get a copy of the program:

  git clone https://github.com/hmdhszd/Golang-MongoDB-Integration-Examples

Go to the project directory:

  cd Golang-MongoDB-Integration-Examples

Run MongoDB

First, run MongoDB in docker:

  docker run -itd --name mongodb -p 27017:27017 ruanbekker/mongodb

Run Golang Program

Then, install packages using go get:

  go mod init Golang-MongoDB

  go get go.mongodb.org/mongo-driver/mongo

1- Check connection to MongoDB

  ▶ go run 1-\ Check\ connection\ to\ MongoDB.go

  Connected to MongoDB!

2- insert a single document to MongoDB - (InsertOne)

  ▶ go run 2-\ insert\ a\ single\ document\ to\ MongoDB\ -\ \(InsertOne\).go

  Inserted a Single Document:  ObjectID("61f93dec8749b8a1f7fce114")

3- insert more than one document to MongoDB - (InsertMany)

  ▶ go run 3-\ insert\ more\ than\ one\ document\ to\ MongoDB\ -\ \(InsertMany\)\ .go

  Inserted multiple documents:  [ObjectID("61f93e171750a6d18be19c5e") ObjectID("61f93e171750a6d18be19c5f") ObjectID("61f93e171750a6d18be19c60")]

4- Updating Documents in MongoDB

  ▶ go run 4-\ Updating\ Documents\ in\ MongoDB.go

  Matched 1 documents and updated 1 documents.

5- Find One Document in MongoDB

  ▶ go run 5-\ Find\ One\ Document\ in\ MongoDB.go 

  Found a single document: {Name:hamid Age:31 City:Paris}

6- Find Multiple Documents in MongoDB

  ▶ go run 6-\ Find\ Multiple\ Documents\ in\ MongoDB.go 
  Found multiple documents (array of pointers): [{Name:hamid Age:31 City:Paris} {Name:hamid Age:30 City:Paris} {Name:James Age:32 City:New York} {Name:Frankie Age:31 City:Vegas} {Name:hamid Age:30 City:Paris} {Name:James Age:32 City:New York} {Name:Frankie Age:31 City:Vegas} {Name:hamid Age:30 City:Paris} {Name:James Age:32 City:New York} {Name:Frankie Age:31 City:Vegas}]
  
  hamid
  31
  Paris

7- Delete One Document in MongoDB

  ▶ go run 7-\ Delete\ One\ Document\ in\ MongoDB.go 

  Deleted 1 documents in the trainers collection

8- Delete Many Documents in MongoDB

  ▶ go run 8-\ Delete\ Many\ Documents\ in\ MongoDB.go 

  Deleted 9 documents in the trainers collection
Similar Resources

Firebird RDBMS sql driver for Go (golang)

firebirdsql (Go firebird sql driver) Firebird RDBMS http://firebirdsql.org SQL driver for Go Requirements Firebird 2.5 or higher Golang 1.13 or higher

Dec 20, 2022

Go MySQL Driver is a MySQL driver for Go's (golang) database/sql package

Go-MySQL-Driver A MySQL-Driver for Go's database/sql package Features Requirements Installation Usage DSN (Data Source Name) Password Protocol Address

Jan 4, 2023

Lightweight Golang driver for ArangoDB

Arangolite Arangolite is a lightweight ArangoDB driver for Go. It focuses on pure AQL querying. See AranGO for a more ORM-like experience. IMPORTANT:

Sep 26, 2022

Golang client for redislabs' ReJSON module with support for multilple redis clients (redigo, go-redis)

Go-ReJSON - a golang client for ReJSON (a JSON data type for Redis) Go-ReJSON is a Go client for ReJSON Redis Module. ReJSON is a Redis module that im

Dec 25, 2022

redis client implement by golang, inspired by jedis.

godis redis client implement by golang, refers to jedis. this library implements most of redis command, include normal redis command, cluster command,

Dec 6, 2022

Go Memcached client library #golang

About This is a memcache client library for the Go programming language (http://golang.org/). Installing Using go get $ go get github.com/bradfitz/gom

Jan 8, 2023

Neo4j REST Client in golang

DEPRECATED! Consider these instead: https://github.com/johnnadratowski/golang-neo4j-bolt-driver https://github.com/go-cq/cq Install: If you don't ha

Nov 9, 2022

Neo4j client for Golang

neoism - Neo4j client for Go Package neoism is a Go client library providing access to the Neo4j graph database via its REST API. Status System Status

Dec 30, 2022

Type-safe Redis client for Golang

Redis client for Golang ❤️ Uptrace.dev - distributed traces, logs, and errors in one place Join Discord to ask questions. Documentation Reference Exam

Jan 1, 2023
Go-mongodb - Practice Go with MongoDB because why not

Practice Mongo DB with Go Because why not. Dependencies gin-gonic go mongodb dri

Jan 5, 2022
💲 Golang, Go Fiber, RabbitMQ, MongoDB, Docker, Kubernetes, GitHub Actions
💲 Golang, Go Fiber, RabbitMQ, MongoDB, Docker, Kubernetes, GitHub Actions

Bank Projeto para simular empréstimos financeiros em um banco para clientes Tecnologias Utilizadas Golang MongoDB RabbitMQ Github Actions Docker Hub D

Dec 9, 2022
Go-odm, a Golang Object Document Mapping for MongoDB.
Go-odm, a Golang Object Document Mapping for MongoDB.

A project of SENROK Open Source Go ODM Go-odm, a Golang Object Document Mapping for MongoDB. Table of contents Features Installation Get started Docum

Nov 4, 2022
Mongo Go Models (mgm) is a fast and simple MongoDB ODM for Go (based on official Mongo Go Driver)
Mongo Go Models (mgm) is a fast and simple MongoDB ODM for Go (based on official Mongo Go Driver)

Mongo Go Models Important Note: We changed package name from github.com/Kamva/mgm/v3(uppercase Kamva) to github.com/kamva/mgm/v3(lowercase kamva) in v

Jan 2, 2023
The MongoDB driver for Go

The MongoDB driver for Go This fork has had a few improvements by ourselves as well as several PR's merged from the original mgo repo that are current

Jan 8, 2023
The Go driver for MongoDB
The Go driver for MongoDB

MongoDB Go Driver The MongoDB supported driver for Go. Requirements Installation Usage Bugs / Feature Reporting Testing / Development Continuous Integ

Dec 31, 2022
Qmgo - The Go driver for MongoDB. It‘s based on official mongo-go-driver but easier to use like Mgo.

Qmgo English | 简体中文 Qmgo is a Go driver for MongoDB . It is based on MongoDB official driver, but easier to use like mgo (such as the chain call). Qmg

Dec 28, 2022
Simple key-value store abstraction and implementations for Go (Redis, Consul, etcd, bbolt, BadgerDB, LevelDB, Memcached, DynamoDB, S3, PostgreSQL, MongoDB, CockroachDB and many more)

gokv Simple key-value store abstraction and implementations for Go Contents Features Simple interface Implementations Value types Marshal formats Road

Dec 24, 2022
Data access layer for PostgreSQL, CockroachDB, MySQL, SQLite and MongoDB with ORM-like features.
Data access layer for PostgreSQL, CockroachDB, MySQL, SQLite and MongoDB with ORM-like features.

upper/db is a productive data access layer (DAL) for Go that provides agnostic tools to work with different data sources

Jan 3, 2023
A MongoDB compatible embeddable database and toolkit for Go.
A MongoDB compatible embeddable database and toolkit for Go.

lungo A MongoDB compatible embeddable database and toolkit for Go. Installation Example Motivation Architecture Features License Installation To get s

Jan 3, 2023