---
# System prepended metadata

title: Migration Mongodb
tags: [Database, Migration, Research, Plando, Mongodb]

---

# Migration Mongodb

###### tags: `Research` `Database` `Mongodb` `Migration` `Plando`

## :memo: Links
We start looking into solutions for mongodb migrations. I already know some tools for use in node, but mongo is not sql based database, so it migrations will became tied to the language on where it was writem.

Node is a good language, but is not for infra and systems. Go is our language for system. Migrations are systems, so we are looking into solutions with go.

- [go and migration](https://medium.com/@eminetto/data-migration-with-golang-and-mongodb-d2930e7f3b8a)
- [node and migration](https://www.freecodecamp.org/news/how-to-automate-database-migrations-in-mongodb-d6b68efe084e/)

## Command interface

I choosed the make script, a commom way to use commands, of interpreted or compiled codes.

```
make migrate new description-of-migration
make migrate up
make migrate down
```

Migration is a operation to production and develpment enviroments, but for enviroment is need of specific type of migration, the seeds.

```
make seed new description-of-seed
make seed up
make seed down
```

For use this I have looked into the following link:

- [passing arguments to make run in Stackoverflow](https://stackoverflow.com/questions/2214575/passing-arguments-to-make-run)

## Scripts

### drop collection


```go
	db.C("projects").coll.DropCollection()
```
:::info
 :book: Reference: 
:::

### create collection
```go
	db.Run(bson.D{{Name: "create", Value: "projects"}}, nil)
```
:::info
 :book: Reference: 
:::

### insert data
```go
	db.C("projects").Insert(bson.M{
	    "name": "plando-development",
	    "endDate": "2020-05-30T00:00:00.000+00:00",
	})
```
:::info
 :book: Reference: 
:::

### remove data
```go
    db.C("projects").Remove(bson.M{
        "name": "plando-development",
    })
```
:::info
 :book: Reference: 
:::

`bson.M` is a Map type from bson, the mongodb type model.
## Automation

links:
- [docker compose with command after run](https://github.com/docker/compose/issues/1809)