I'm using MongoDB docker (4.4.x) image as my DB for NestJS backend. One of the API is triggered by a webhook of my payment gateway. Since its a payment related DB ops, I use transactions for ACID. The problem is, after I start session, then transaction & try to find one document (the very first query in the transaction), It throws an error :
{
"ok": 0,
"code": 20,
"codeName": "IllegalOperation",
"name": "MongoError"
}
I then switched to the MongoDB Atlas dev server and the whole transaction works flawlessly. Which leads me to believe that, there is something wrong with my installation of mongo docker image.
My docker-compose.yaml file:
version: '3'
services:
database:
image: 'mongo'
container_name: 'mongoDbDev'
environment:
- MONGO_INITDB_ROOT_USERNAME=root
- MONGO_INITDB_ROOT_PASSWORD=789512346
volumes:
- ./mongo-volume:/data/db
ports:
- '27017:27017'
The mongo-volume
directory is located in ~/Documents/Workspace/Docker/mongodb/
I tried this stackoverflow solution but did not work. Which TLDR; Changing permissions to the ./mongo-volume
folder.
Additional info,
- I user docker-compose command without sudo (tried with sudo, did not work)
- I have to use docker with sudo command, post installation steps did not work for me