MongoDB v2.4.9 Quick Action Record

Source: Internet
Author: User
Tags create mongodb

Reference Link: http://www.runoob.com/mongodb/mongodb-tutorial.html
Oschina Link: https://gitee.com/dhclly/icedog.script.test/tree/devp-work/momgodb/v2.4.9

Quickly open a MongoDB console instance

First go to the bin directory that contains the MongoDB run program, or the path of MongoDB has been added to the global path variable

By default, create a data folder in the D packing directory, and create a db folder and log folder

For the console to close, close the cmd window directly, or press ctrl+c and then enter close as prompted y

In the following Windows Services Section, running through the configuration file is also applicable to the CMD console instance, just performmongod --config your-config-path

Fast-cmd-run.bat
@echo offif not exist  D:\data\db (md D:\data\db) else (echo Folder ‘db‘ is exist)if not exist  D:\data\log (md D:\data\log) else (echo Folder ‘log‘ is exist)mongod.exe --dbpath D:\data\db --rest --bind_ip localhost --port 27017

The above for the D packing directory to create a data folder, and then create a db folder and log folder, and bind IP to Localhsot, while opening the restful API

Fast-cmd-run-with-log.bat
@echo offif not exist  D:\data\db (md D:\data\db) else (echo Folder ‘db‘ is exist)if not exist  D:\data\log (md D:\data\log) else (echo Folder ‘log‘ is exist)mongod.exe --dbpath D:\data\db --rest --bind_ip localhost --port 27017 --logpath D:\data\log\db.log --logappend

Above the log version, anything will be output to the log, not the console

To start a MongoDB instance as a Windows system service

Scripts are best performed using the command-line window of administrator privileges to avoid the absence of permissions
If you configure MongoDB as a Windows service, you must have a log
At the same time, DBPath and LogPath must be absolute paths , and the relative path service cannot start

Fast-server-create.bat
@echo offif not exist  D:\data\db (md D:\data\db) else (echo Folder ‘db‘ is exist)if not exist  D:\data\log (md D:\data\log) else (echo Folder ‘log‘ is exist)mongod.exe --rest --bind_ip localhost --port 27017 --serviceName "MongoDBService" --serviceDisplayName "MongoDB Service For IceDog" --serviceDescription "this is a  mongo database service" --install --logpath D:\data\log\db.log --logappend --dbpath D:\data\dbnet start MongoDBService

The creation of a service script only needs to be performed once and can be simplified by placing most of the configuration in the config configuration file to simplify the command line

Icedog-mongod.config

rest=truebind_ip=localhostport=27017logpath=D:\data\log\db.log logappend=truedbpath=D:\data\db
if not exist  D:\data\db (md D:\data\db) else (echo Folder ‘db‘ is exist)if not exist  D:\data\log (md D:\data\log) else (echo Folder ‘log‘ is exist)mongod --config D:\data\config\icedog-mongod.config --serviceName "MongoDBService" --serviceDisplayName "MongoDB Service For IceDog" --serviceDescription "this is a  mongo database service" --installnet start MongoDBService

v2.4.x version can also be configured by config file to create MongoDB service, as shown above, configuration file description address: https://docs.mongodb.com/v2.4/reference/ The configuration-options/,3.0 version of the configuration file uses YAML syntax to write the configuration file, but is backwards compatible.

Fast-server-delete.bat
@echo offmongod --remove --serviceName "MongoDBService"
@echo offnet stop MongoDBServicesc delete MongoDBService

Prioritize using the APIs provided by MongoDB to remove services

If the service is not stopped, the direct deletion will be an error, you can first by pressing the ctrl+shift+esc Task Manager, then find mongod.exe and shut down, and then execute sc delete MongoDBService , if still not, find the system registry, delete the service registry information, usually the path in: HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services Find the name of your service, then delete the entire folder, not yet, refer to this article.

Fast-server-start.bat
@echo offnet start MongoDBService
@echo offsc start MongoDBService

Two commands can do the same

Fast-server-stop.bat
@echo offnet stop MongoDBService
@echo offsc stop MongoDBService

Two commands can do the same

MongoDB v2.4.9 Quick Action Record

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.