mongodoki

2019-08-15

mongodoki是什么

什么是mongodoki,A tool to on-the-fly run MongoDB as a Docker Container, data restoring included

mongodoki使用教程帮助文档

Mongodoki

A little library and command-line tool to on-the-fly run MongoDB as a Docker Container.

travis buildCoverage StatusKnown Vulnerabilitiesnpm versionCommitizen friendly

Prerequisites

Dockermust be installed and running on your machine, Mongodoki does the rest. Thus, no need to natively install MongoDB on your machine.

Node.js version 7.10.0 or 8.x.x


Quick Start as library

npm install mongodoki

then:

const Mongodoki = require('mongodoki').Mongodoki;
const md = new Mongodoki();

//create and start a mongo:latest Docker container and return a MongoDB Db instance, default port: 27017, db name: local, container name: mongodoki-container
//db is a mongodb#MongoClient instance.
const db = await md.getDB();

//use Mongo Db instance through official mongodb drivers
const collections = await db.collections();
...

Quick Start as command line tool

npm install -g mongodoki
$ mongodoki --help

;)

Example:

$ mongodoki start -n awesomedb

$ mongodoki stop awesomedb

API

Instantiating Mongodoki

const md = new Mongodoki([config]); 

configobject _is optional_; when missing, it defaults to:

{ tag: 'latest', containerName: 'mongodoki', hostPort: 27017, reuse: false }

where:

tag- is the preferred tag for the official Docker Image;

containerName- is the name of the container to create;

port- is the MongoDB port at which dockerized mongod will listen;

reuse- boolean, if true it will try to reuse an existing container avoiding building a new one;

volume- optional, is an object with two properties:

{hostDir: <abs_path>, containerDir: <abs_path>'}

when volumeis specified it allows to bind a directory with path in hostDirin the local host machine to a container volume path specified by the containerDirproperty. All paths are absoluteand hostDirdirectory must be included in File SharingDocker Preferences.

Specifying a volumebinding allows to locally persist the database data in the host machine, preserving it between containers start/stop/create/destroy lifecycle.

Example:

let md = new Mongodoki( {containerName: 'myMongo', reuse: false, volume: {hostDir: '/Users/diego/temp', containerDir: '/data/db'}} );

Mongodoki Methods

All methods return a Promise.

Create the Container (eventually import a data dump) and connect to the DB

getDB(dbName = 'local' [, timeout = 60000] [, dbDumpPath] )

Returns a Promise with a connected MongoClientobject in case of success;

Parameters:

dbName- name of the dockerized DB to connect to;

timeout- _optional_, max time to wait for the container/db startup, in milliseconds (default: 60000);

dbDumpPath- _optional_, root directory path of a db dump (previously created by MongoDB mongodumptool); in case of a successful import the created database on the container will contain the restored data.


Manage the Container

stop();
remove();
stopAndRemove();

respectively, they stop, remove and stop+remove the Docker container. Removing a container also removes all the created (and unused) Docker Volumes on the host machine (same as running docker volume prunecommand).


License - "MIT License"

Copyright (c) 2017 Antonio Pintus, Vivocha S.p.A.

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.


上一篇:rql
下一篇:arrest
相关教程
关注微信

扫码加入 JavaScript 社区

相关文章
暂无相关文章

首次访问,需要验证
微信扫码,关注即可
(仅需验证一次)

欢迎加入 JavaScript 社区

号内回复关键字:

回到顶部