Which files should be ignored by Git in a Mongodb database?

Asked

Viewed 70 times

0

I am creating an application with Mongodb and after initializing the repository, I entered the command git add * in the root directory of my project. When I went to upload the repository to Github, I uploaded a Warning of large files... Which files should be ignored by Git versioning?? The structure of my project is like this:


├── data
│   ├── collection-0-5707178860372730613.wt
│   ├── collection-0--7787953897620321908.wt
│   ├── collection-2-5707178860372730613.wt
│   ├── collection-4-5707178860372730613.wt
│   ├── diagnostic.data
│   │   ├── metrics.2020-06-11T21-33-12Z-00000
│   │   ├── metrics.2020-06-11T21-33-26Z-00000
│   │   └── metrics.interim
│   ├── index-1-5707178860372730613.wt
│   ├── index-1--7787953897620321908.wt
│   ├── index-3-5707178860372730613.wt
│   ├── index-5-5707178860372730613.wt
│   ├── index-6-5707178860372730613.wt
│   ├── journal
│   │   ├── WiredTigerLog.0000000002
│   │   ├── WiredTigerPreplog.0000000001
│   │   └── WiredTigerPreplog.0000000002
│   ├── _mdb_catalog.wt
│   ├── mongod.lock
│   ├── sizeStorer.wt
│   ├── storage.bson
│   ├── WiredTiger
│   ├── WiredTigerLAS.wt
│   ├── WiredTiger.lock
│   ├── WiredTiger.turtle
│   └── WiredTiger.wt
├── routes.ts
└── server.ts

2 answers

1

The files in data are precisely from Mongo and should be ALL ignored. We should not add database data to the repository. It doesn’t even make sense that they are next to your code and should be moved anywhere else (I see no reason not to use the default database).

If you want your application to have an initial status and/or changes to the database are controlled via code you should use scripts and Migrations for this.

With the scripts in a directory of your repository you can control all DDL and DML changes. There are numerous ways to do this, but it is already outside the scope of this question and will depend on several factors deciding which strategy to adopt.

  • Thank you very much! It really doesn’t make sense to leave the bank next to the server code. Thanks for the help!

1


To solve this specific problem it is necessary to create a file .gitignore at the root of your project’s directory and add the directory data/ as a line from this file.

$touch .gitignore && echo data/ >> .gitignore

You should commit this file (add to versioning control).

$git add .gitignore
$git commit -m "criação gitignore"

Remove from the versioning control the directory data/.

$git rm -r --cached data/ 
  • Thank you so much for your help!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.