I can install the MongoDB service, but I cannot run it. Does anyone know how to do it?"
Thereβs no services.mongodb for the dev.idx file yetβ¦ But you still start the mongodb services by your own.
The mongodb package brings a program called mongod
which means to be the mongo daemon, if you try to run mongod it will fail because we need to do some tweaks before.
- Create a directory in your workspace, for instance
mongodb
- Create two files inside that directory, for instance
start.sh
andmongo.conf
with the following content:
mongo.conf file (referenced by mongo page for more info):
processManagement:
fork: true
net:
bindIp: localhost
port: 27017
storage:
dbPath: "./mongodb/var/lib/mongo"
systemLog:
destination: file
path: "./mongodb/var/log/mongodb/mongod.log"
logAppend: true
start.sh file:
#!/usr/bin/bash
# create inside our directory that we created as `mongodb`
# the following directories which saves the data and log of the mongo service
mkdir -p ./mongodb/var/lib/mongo/
mkdir -p ./mongodb/var/log/mongodb/
# run the mongo daemon with the configuration that we have created above
mongod --config ./mongodb/mongo.conf
- Start the service everytime that we access to our workspace (in the dev.idx file):
{pkgs, ...}: {
idx.workspace.onStart = {
mongo-db = "./mongodb/start.sh";
};
}
And this should be the final directory tree if we applied the above and run the service:
./my-blank-app/
βββ .idx
β βββ dev.nix
βββ mongodb
β βββ mongo.conf
β βββ start.sh
β βββ var
β βββ lib
β β βββ mongo
β β βββ collection-0--5619253475827229124.wt
β β βββ collection-2--5619253475827229124.wt
β β βββ collection-4--5619253475827229124.wt
β β βββ diagnostic.data
β β β βββ metrics.2024-08-15T12-11-51Z-00000
β β β βββ metrics.interim
β β βββ index-1--5619253475827229124.wt
β β βββ index-3--5619253475827229124.wt
β β βββ index-5--5619253475827229124.wt
β β βββ index-6--5619253475827229124.wt
β β βββ journal
β β β βββ WiredTigerLog.0000000001
β β β βββ WiredTigerPreplog.0000000001
β β β βββ WiredTigerPreplog.0000000002
β β βββ _mdb_catalog.wt
β β βββ mongod.lock
β β βββ sizeStorer.wt
β β βββ storage.bson
β β βββ WiredTiger
β β βββ WiredTigerHS.wt
β β βββ WiredTiger.lock
β β βββ WiredTiger.turtle
β β βββ WiredTiger.wt
β βββ log
β βββ mongodb
β βββ mongod.log
βββ README.md
Thank you for your suggestion. I tried the solution you provided, but unfortunately, it didnβt solve my problem. Instead, I encountered a new error:
Also, I created a new project and set it up as you explained it, but I get the same error.
Oops, sorry I had forgotten to say to add executable permission for the start.sh
chmod +x ./mongodb/start.sh
And it should work normally.
Thank you very much! It worked.