mongodbapp icon indicating copy to clipboard operation
mongodbapp copied to clipboard

Allow user to create their own mongo config file

Open mjaustin2 opened this issue 9 years ago • 7 comments

Sorry, I'm too lazy to fork and create a pull request for a 7 line change, but would be nice if the user could have their own mongodb.conf to configure options.

The code below changes startServer to check for a file in the user home directory, and if found add it to the command arguments.

Full File attached: AppDelegate

    func startServer() {
        self.task = NSTask()
        self.pipe = NSPipe()
        self.file = self.pipe.fileHandleForReading

        if let path = NSBundle.mainBundle().pathForResource("mongod", ofType: "", inDirectory: "Vendor/mongodb") {
            self.task.launchPath = path
        }

        var args = ["--dbpath", self.dataPath, "--nounixsocket", "--logpath", "\(self.logPath)/mongo.log"]

        // Check if user config file exists and add to arguments (~/.mongodb.conf)
        let configFile = (NSHomeDirectory() + "/.mongodb.conf")
        let fileManager = NSFileManager.defaultManager()
        if fileManager.fileExistsAtPath(configFile) {
            args.append("--config")
            args.append(configFile)
        }

        self.task.arguments = args
        self.task.standardOutput = self.pipe

        print("Run mongod")

        self.task.launch()
    }

mjaustin2 avatar Jun 10 '16 19:06 mjaustin2

Not even a comment to tell me how bad my code is? :-)

mjaustin2 avatar Jun 17 '16 14:06 mjaustin2

Hi there. Couldn't review this before. I will try to test it soon. A PR will make it much easier for me.

gcollazo avatar Jun 17 '16 18:06 gcollazo

Any update on this? I'm running into the same issue, and it would be nice to configure this.

arciisine avatar Jan 02 '17 02:01 arciisine

Hi @arciisine. I haven't been able to try this out. This is not a feature I personally use. I would be willing to merge a pull request that worked.

gcollazo avatar Jan 02 '17 18:01 gcollazo

I tried to fix this, but mainly I have another problem here, binding IP Address and dbPath is configured in the command line argument, so whatever config I pass here will be overwritten.

makan1869 avatar Jan 13 '17 05:01 makan1869

There, I fixed it and made a PR. As @makan1869 correctly says, the command line arguments at launch would override the file settings, so those needed to be replaced with the file's values. Disclaimer: this is the first Swift code that I ever write so go easy on it & let me know whatever needs to be fixed!

juliangrigera avatar Jul 24 '17 14:07 juliangrigera

I would recommend something more UNIX-y, such as ~/.local/etc/mongod.conf, or, more macOS-y, such as ~/Library/Preferences/io.blimp.MongoDB.conf to go alongside the existing io.blimp.MongoDB.plist used for actual GUI application preferences/cookies. (Edit to note: my dotfiles are already cluttered enough at the top level. 😜)

I, too, ran into this need, in order to specify storage:directoryPerDB:. An alternative that would satisfy my requirements would be the ability to specify additional command-line arguments, --directoryperdb, of which -f [ --config ] arg to specify a configuration file explicitly would satisfy this issue as well.

8 month update: Now I have a need to apply a tweak to wiredTiger.engineConfig.cacheSizeGB

amcgregor avatar Jan 14 '22 04:01 amcgregor