Install MongoDB prebuilt binaries via npm with cross platform support.
npm install mongodb-prebuilt-crossmongodb command for use on the command line without having to compile anything.
package.json as a devDependency:
shell
npm install mongodb-prebuilt-cross --save-dev
`
You can also use the -g flag (global) to symlink it into your PATH:
`shell
npm install -g mongodb-prebuilt-cross
`
If that command fails with an EACCESS error you may have to run it again with sudo:
`shell
sudo npm install -g mongodb-prebuilt
`
Now you can just run mongod to run mongodb:
`
mongod
`
Complete list of programs:
- bsondump
- mongo
- mongod
- mongodump
- mongoexport
- mongofiles
- mongoimport
- mongooplog
- mongoperf
- mongorestore
- mongos
- mongosniff
- mongostat
- mongotop
About
Works on Mac, Windows, Linux and Solaris OSes that MongoDB supports.
The version numbers of this module DO NOT match the version number of the offical MongoDB releases. By default, latest production release will be selected. Different version is set via mongodb-version
option:
`js
npm install --mongodb-version=3.2.0 mongodb-prebuilt
`
Programmatic usage
`js
var mongodb_prebuilt = require('mongodb-prebuilt');
mongodb_prebuilt.start_server({}, function(err) {
if (err) {
console.log('mongod didnt start:', err);
} else {
console.log('mongod is started');
}
});
`
start_server(opts, callback)
$3
Type: object
Hash of options.
$3
Type: function
Function called when the mongod is started or returned an error
Options
$3
Type: string
Optional version of MongoDB can be specified, if it doesn't match latest
version, and it is a first time you are running this version, mongodb-prebuilt
will have to go through the install process first.
`js
mongodb_prebuilt.start_server({
version: "3.2.0"
}, function(err) {
if (!err) console.log('server started');
});
`
$3
Type: function
Optional arguments that are going to be passed to mongod, if argument doesn't
have a value, set that value to true. To see complete list of supported
arguments for your version run:
`shell
mongod --help
`
example of start_server with arguments
`js
mongodb_prebuilt.start_server({
args: {
port: 27017,
quiet: true,
dbpath: __dirname + ......
}
})
`
$3
Type: function
Optional logs handler.
`js
mongodb_prebuilt.start_server({
logs_callback: logs_callback
}, function(err) {});
function logs_callback(buffer) {
console.log("log message:", buffer.toString());
}
`
$3
Type: boolean
Default: false
Will automatically shutdown the mongodb server when the parent process either exits or throws an uncaught exception
Logging
To see logs in stdout, set environment variable DEBUG to mongodb
*nix
`shell
export DEBUG=mongodb
// without export
DEBUG=mongodb node myapp.js
`
windows
`shell
set DEBUG=mongodb
`
Download Proxy
If you require proxy to reach outside networks, you may do it by:
* pass extra argument to npm install
`js
npm install --https-proxy="https://example.com"
`
* set environment variable with https_proxy
`shell
*nix
export https_proxy="https://example.com"
win32
set https_proxy="https://example.com"
``