0
0
mirror of https://github.com/naturalcrit/homebrewery.git synced 2026-03-24 12:58:11 +00:00

Created Importing Mongo dump to local (macos) (markdown)

Gazook89
2025-07-29 15:06:50 -05:00
parent ae63addca1
commit 4ffab782db

@@ -0,0 +1,115 @@
*This is just an obsidian note I made for myself a day after going through this process. It may not, and likely isn't, 100% accurate or the best way to do something.*
7/29/2025
CalculusChild did an export from Mongo Atlas of our database, something that I think is actually referred to as a "snapshot". It was a big *gzip* file, or `abc.tar.gz` file extension, and contained `.wt` or "wireTiger" files.
This data dump is *not* used by mongorestore. So that documentation won't work for importing the DB into a local mongo db.
Here is what I did, warts and all. Also note, I did find the Mongo Chat AI to be marginally useful.
!! Be sure you have the same Mongo version as the live Homebrewery site is using at the time of the data export. At this time, that was Mongo Community 6.0.
!! Note that I am using MacOS with the Homebrew package manager. Any commands that start with `brew` stem from that package manager. And it shouldn't be confused for the *Homebrewery*.
## 1. Find the file path of your current database.
You can do that with the mongo terminal. You need to have Mongo running, and then run this command:
```zsh
db.serverCmdLineOpts()
```
Which should get you output that looks somewhat like this:
```zsh
{
argv: [
'/opt/homebrew/opt/mongodb-community@6.0/bin/mongod',
'--config',
'/opt/homebrew/etc/mongod.conf'
],
parsed: {
config: '/opt/homebrew/etc/mongod.conf',
net: { bindIp: '127.0.0.1, ::1', ipv6: true },
storage: { dbPath: '/opt/homebrew/var/mongodb' },
systemLog: {
destination: 'file',
logAppend: true,
path: '/opt/homebrew/var/log/mongodb/mongo.log'
}
},
ok: 1
}
```
The file path of your database is in the parsed.storage.dbPath property. For me, on MacOS, it's `/opt/homebrew/var/mongodb`. Keep in mind that these directories might be 'hidden directories', not immediately viewable in a file explorer application.
Note, or open, that directory so have you it available.
## 2. Stop your Mongo service
Stop any mongo service you have running currently. Keep in mind that Mongo typically runs all the time in the background, starting when your computer boots up. So just double check it is stopped.
For me, with MacOS and using the Homebrew package manager, I can do this:
```zsh
brew services list
```
Which will give me an output like:
```zsh
Name Status User File
colima started Me ~/Library/LaunchAgents/homebrew.mxcl.colima.plist
mongodb-community none
mongodb-community@5.0 none
mongodb-community@6.0 started Me ~/Library/LaunchAgents/homebrew.mxcl.mongodb-community@6.0.plist
postgresql@14 none
redis none
unbound none
```
I can see that i have a few different installations of mongo and some other stuff, and that Mongo 6.0 is currently running. I want to shut that down with:
```zsh
brew services stop mongodb/brew/mongodb-community@6.0
```
## 3. Paste downloaded db into current db folder, or into new directory
This is where things split between what *I* did, and what might be possible. What I did was paste the downloaded db contents into the current db directory, overwriting everything that was already there. I did this because I didn't care what was in my original db. If you want to preserve that old data, you may be able to create a new db location by creating a new folder, pasting your downloaded data there. Either way, I think the subsequent steps are likely roughly the same.
To be clear, starting with the tar.gz file, I uncompressed it (on Mac, using Archive Utility) and then copied all the inner contents of that and pasted them into `/opt/homebrew/var/mongodb` and overwriting all. If i wanted to preserve the old stuff, I would try pasting into `/opt/homebrew/var/mongodb-2`.
## 4. Reset the db path and start Mongo service
To reset the db path, I did this:
```zsh
mongod --dbpath /opt/homebrew/var/mongodb --repair
```
Followed by restarting the mongo service:
```zsh
brew services start mongodb-community@6.0
```
And checking the status with:
```zsh
brew services list
```
And hoping it says "started" and not "error".
## 5. Use Mongo Compass to connect
At this point I switched to Mongo Compass GUI to connect the server and check that I could connect, and look for the db name I needed to connect to. As downloaded, the database name that I had to point towards was `heroku_cjpfxl1z`, not `homebrewery` as I had earlier (and is the suggested name in the Homebrewery github repo readme when creating the mongo server initially).
## 6. Update db.js in repo
I'm not sure this is or should be necessary, but it made it work for me: I had to update the `server/db.js` file in the Homebrewery repo so that the app tried to connect to the correct db:
```js
// ...
const getMongoDBURL = (config)=>{
return config.get('mongodb_uri') ||
config.get('mongolab_uri') ||
'mongodb://127.0.0.1/heroku_cjpfxl1z'; // update this line
};
// ...
```
## 7. Restart app
At this point I could start up my homebrewery app and it would connect.
------
I assume that I don't necessarily need to update `db.js` but instead could use a config parameter somewhere. Alternatively, I couldn't find where i could change the name of an existing DB to match 'homebrewery' that i had originally-- the mongo docs suggest it isn't possible, but that you can copy all the collections of a db to a new db, renaming it in the process.
I also had a problem where the Vault wouldn't search because of an issue with a missing `text` index for `title` query, which seems odd-- it seems like that should be a part of the export of the live site mongo db. Especially since there are plenty of Indexes that came with it. But I just added a text index for title and it worked again.