Tuesday, 15 August 2017

BIGDATA: MONGODB: START UP;EXAMPLES

BIGDATA MONGODB STARTUP PROCESSES: CASE

*** 
Source: https://docs.mongodb.com/manual/tutorial/manage-mongodb-processes/ 

Manage mongod Processes

MongoDB runs as a standard program. You can start MongoDB from a command line by issuing the mongodcommand and specifying options. For a list of options, see the mongod reference. MongoDB can also run as a Windows service. For details, see Configure a Windows Service for MongoDB Community Edition. To install MongoDB, see Install MongoDB.
The following examples assume the directory containing the mongod process is in your system paths. Themongod process is the primary database process that runs on an individual server. mongos provides a coherent MongoDB interface equivalent to a mongod from the perspective of a client. The mongo binary provides the administrative shell.
This document discusses the mongod process; however, some portions of this document may be applicable to mongos instances.

Start mongod Processes

By default, MongoDB listens for connections from clients on port 27017, and stores data in the /data/dbdirectory.
On Windows, this path is on the drive from which you start MongoDB. For example, if you do not specify a --dbpath, starting a MongoDB server on the C:\ drive stores all data files in C:\data\db.
To start MongoDB using all defaults, issue the following command at the system shell:
mongod

Specify a Data Directory

If you want mongod to store data files at a path other than /data/db you can specify a dbPath. ThedbPath must exist before you start mongod. If it does not exist, create the directory and the permissions so that mongod can read and write data to this path. For more information on permissions, see the security operations documentation.
To specify a dbPath for mongod to use as a data directory, use the --dbpath option. The following invocation will start a mongod instance and store data in the /srv/mongodb path
mongod --dbpath /srv/mongodb/

Specify a TCP Port

Only a single process can listen for connections on a network interface at a time. If you run multiple mongodprocesses on a single machine, or have other processes that must use this port, you must assign each a different port to listen on for client connections.
To specify a port to mongod, use the --port option on the command line. The following command starts mongod listening on port 12345:
mongod --port 12345
Use the default port number when possible, to avoid confusion.

Start mongod as a Daemon

To run a mongod process as a daemon (i.e. fork), and write its output to a log file, use the --fork and --logpath options. You must create the log directory; however, mongod will create the log file if it does not exist.
The following command starts mongod as a daemon and records log output to /var/log/mongodb.log.
mongod --fork --logpath /var/log/mongodb.log

Additional Configuration Options

For an overview of common configurations and deployments for common use cases, see Run-time Database Configuration.

Stop mongod Processes

In a clean shutdown a mongod completes all pending operations, flushes all data to data files, and closes all data files. Other shutdowns are unclean and can compromise the validity of the data files.
To ensure a clean shutdown, always shutdown mongod instances using one of the following methods:

Use shutdownServer()

Shut down the mongod from the mongo shell using the db.shutdownServer() method as follows:
use admin
db.shutdownServer()
Calling the same method from a init script accomplishes the same result.
For systems with authorization enabled, users may only issue db.shutdownServer() when authenticated to the admin database or via the localhost interface on systems without authentication enabled.

Use --shutdown

From the Linux command line, shut down the mongod using the --shutdown option in the following command:
mongod --shutdown

Use CTRL-C

When running the mongod instance in interactive mode (i.e. without --fork), issue Control-C to perform a clean shutdown.

Use kill

From the Linux command line, shut down a specific mongod instance using one of the following commands:
kill <mongod process ID>
kill -2 <mongod process ID>
WARNING
Never use kill -9 (i.e. SIGKILL) to terminate a mongod instance.

Stop a Replica Set

Procedure

If the mongod is the primary in a replica set, the shutdown process for this mongod instance has the following steps:
  1. Check how up-to-date the secondaries are.
  2. If no secondary is within 10 seconds of the primary, mongod will return a message that it will not shut down. You can pass the shutdown command a timeoutSecs argument to wait for a secondary to catch up.
  3. If there is a secondary within 10 seconds of the primary, the primary will step down and wait for the secondary to catch up.
  4. After 60 seconds or once the secondary has caught up, the primary will shut down.

Force Replica Set Shutdown

If there is no up-to-date secondary and you want the primary to shut down, issue the shutdown command with the force argument, as in the following mongo shell operation:
db.adminCommand({shutdown : 1, force : true})
To keep checking the secondaries for a specified number of seconds if none are immediately up-to-date, issue shutdown with the timeoutSecs argument. MongoDB will keep checking the secondaries for the specified number of seconds if none are immediately up-to-date. If any of the secondaries catch up within the allotted time, the primary will shut down. If no secondaries catch up, it will not shut down.
The following command issues shutdown with timeoutSecs set to 5:
db.adminCommand({shutdown : 1, timeoutSecs : 5})
Alternately you can use the timeoutSecs argument with the db.shutdownServer() method:
db.shutdownServer({timeoutSecs : 5})

****
Source: https://docs.mongodb.com/manual/

The MongoDB 3.4 Manual

MONGODB STITCH (BETA)
MongoDB Stitch is a backend as a service that provides an HTTP API to MongoDB, integration with other services, and a declarative rules infrastructure which spans database and service actions. For more information
Welcome to the MongoDB 3.4 Manual! MongoDB is an open-source, document database designed for ease of development and scaling. The Manual introduces key concepts in MongoDB, presents the query language, and provides operational and administrative considerations and procedures as well as a comprehensive reference section. [1]
➤ MongoDB 3.4 Released
For summary of new features in MongoDB 3.4, see Release Notes for MongoDB 3.4.
➤ University Course
M034: New Features and Tools in MongoDB 3.4. M034 is a continuing education course on MongoDB 3.4. In a series of what will be approximately 16 modules, we will introduce marquee 3.4 features in detail.

Community

Getting involved in the MongoDB community is a great way to build relationships with other talented and like minded engineers, increase awareness for the interesting work that you are doing, and sharpen your skills. To learn about the MongoDB community, see Get Involved with MongoDB.

Learning MongoDB

In addition to the documentation, there are many ways to learn to use MongoDB. You can:

Getting Help

If you’re looking for help, you’ll get a quick response to MongoDB questions posted to Stack Overflow or to our mailing listMongoDB, Inc. also offers commercial support and services.

Licensing

For information on MongoDB licensing, see MongoDB Licensing.

Additional Resources

MongoDB, Inc.
The company behind MongoDB.
MongoDB Atlas
Database as a service.
MongoDB Cloud Manager
A cloud-based hosted operations management solution for MongoDB.
MongoDB Ops Manager
Enterprise operations management solution for MongoDB: includes Automation, Backup, and Monitoring.
MongoDB Ecosystem
The documentation available for the drivers, frameworks, tools, and services for use with MongoDB.
[1]The manual is also available as HTML tar.gz and EPUB



***
Source: https://docs.mongodb.com/manual/installation/ 

Install MongoDB


This section of the manual contains tutorials on installation of MongoDB.

Supported Platforms

Changed in version 3.4: MongoDB no longer supports 32-bit x86 platforms.

x86_64

Platform3.4 Community & Enterprise3.2 Community & Enterprise3.0 Community & Enterprise
Amazon Linux 2013.03 and later
Debian 7
Debian 8
RHEL/CentOS 6.2 and later
RHEL/CentOS 7.0 and later
SLES 11
SLES 12
Solaris 11 64-bitCommunity onlyCommunity onlyCommunity only
Ubuntu 12.04
Ubuntu 14.04
Ubuntu 16.04
Windows Server 2008R2 and later
Windows Vista and later
OS X 10.7 and later

ARM64

Platform3.4 Community & Enterprise
Ubuntu 16.04

PPC64LE (MongoDB Enterprise Edition)

Platform3.4 Enterprise
RHEL/CentOS 7.1
Ubuntu 16.04

s390x (MongoDB Enterprise Edition)

Platform3.4 Enterprise
RHEL/CentOS 7.2
SLES 11
SLES 12
Ubuntu 16.04

Tutorials

MongoDB Community Edition

Install on Linux
Install MongoDB Community Edition and required dependencies on Linux.
Install on OS X
Install MongoDB Community Edition on OS X systems from Homebrew packages or from MongoDB archives.
Install on Windows
Install MongoDB Community Edition on Windows systems and optionally start MongoDB as a Windows service.

MongoDB Enterprise

Install on Linux
Install the official builds of MongoDB Enterprise on Linux-based systems.
Install on OS X
Install the official build of MongoDB Enterprise on OS X
Install on Windows
Install MongoDB Enterprise on Windows using the .msi installer.

Additional Resources



 Was this page helpful?

**** 
Source: https://docs.mongodb.com/manual/mongo/

The mongo Shell

Introduction

The mongo shell is an interactive JavaScript interface to MongoDB. You can use the mongo shell to query and update data as well as perform administrative operations.
The mongo shell is a component of the MongoDB distributions. Once you have installed and have started MongoDB, connect the mongo shell to your running MongoDB instance.
Most examples in the MongoDB Manual use the mongo shell; however, many drivers provide similar interfaces to MongoDB.

Start the mongo Shell

IMPORTANT
Ensure that MongoDB is running before attempting to start the mongo shell.
To start the mongo shell and connect to your MongoDB instance running on localhost with default port:
  1. At a prompt in a terminal window (or a command prompt for Windows), go to your <mongodbinstallation dir>:
    cd <mongodb installation dir>
    
  2. Type ./bin/mongo to start mongo:
    ./bin/mongo
    
    If you have added the <mongodb installation dir>/bin to the PATH environment variable, you can just type mongo instead of ./bin/mongo.

Options

When you run mongo without any arguments, the mongo shell will attempt to connect to the MongoDB instance running on the localhost interface on port 27017. To specify a different host or port number, as well as other options, see examples of starting up mongo and mongo reference which provides details on the available options.

.mongorc.js File

When starting, mongo checks the user’s HOME directory for a JavaScript file named .mongorc.js. If found, mongo interprets the content of .mongorc.js before displaying the prompt for the first time. If you use the shell to evaluate a JavaScript file or expression, either by using the --eval option on the command line or by specifying a .js file to mongomongo will read the .mongorc.js file after the JavaScript has finished processing. You can prevent .mongorc.js from being loaded by using the --norc option.

Working with the mongo Shell

To display the database you are using, type db:
db
The operation should return test, which is the default database. To switch databases, issue the use <db>helper, as in the following example:
use <database>
To list the available databases, use the helper show dbs. See also db.getSiblingDB() method to access a different database from the current database without switching your current database context (i.e. db).
You can switch to non-existing databases. When you first store data in the database, such as by creating a collection, MongoDB creates the database. For example, the following creates both the databasemyNewDatabase and the collection myCollection during the insertOne() operation:
use myNewDatabase
db.myCollection.insertOne( { x: 1 } );
  • db refers to the current database.
  • myCollection is the name of the collection.
If the mongo shell does not accept the name of the collection, for instance if the name contains a space, hyphen, or starts with a number, you can use an alternate syntax to refer to the collection, as in the following:
db["3test"].find()

db.getCollection("3test").find()
The mongo shell prompt has a limit of 4095 codepoints for each line. If you enter a line with more than 4095 codepoints, the shell will truncate it.
For more documentation of basic MongoDB operations in the mongo shell, see:

Format Printed Results

The db.collection.find() method returns a cursor to the results; however, in the mongo shell, if the returned cursor is not assigned to a variable using the var keyword, then the cursor is automatically iterated up to 20 times to print up to the first 20 documents that match the query. The mongo shell will prompt Typeit to iterate another 20 times.
To format the printed result, you can add the .pretty() to the operation, as in the following:
db.myCollection.find().pretty()
In addition, you can use the following explicit print methods in the mongo shell:
  • print() to print without formatting
  • print(tojson(<obj>)) to print with JSON formatting and equivalent to printjson()
  • printjson() to print with JSON formatting and equivalent to print(tojson(<obj>))
For more information and examples on cursor handling in the mongo shell, see Iterate a Cursor in the mongo Shell. See also Cursor Help for list of cursor help in the mongo shell.

Multi-line Operations in the mongo Shell

If you end a line with an open parenthesis ('('), an open brace ('{'), or an open bracket ('['), then the subsequent lines start with ellipsis ("...") until you enter the corresponding closing parenthesis (')'), the closing brace ('}') or the closing bracket (']'). The mongo shell waits for the closing parenthesis, closing brace, or the closing bracket before evaluating the code, as in the following example:
> if ( x > 0 ) {
... count++;
... print (x);
... }
You can exit the line continuation mode if you enter two blank lines, as in the following example:
> if (x > 0
...
...
>

Tab Completion and Other Keyboard Shortcuts

The mongo shell supports keyboard shortcuts. For example,
  • Use the up/down arrow keys to scroll through command history. See .dbshell documentation for more information on the .dbshell file.
  • Use <Tab> to autocomplete or to list the completion possibilities, as in the following example which uses <Tab> to complete the method name starting with the letter 'c':
    db.myCollection.c<Tab>
    
    Because there are many collection methods starting with the letter 'c', the <Tab> will list the various methods that start with 'c'.
For a full list of the shortcuts, see Shell Keyboard Shortcuts

Exit the Shell

To exit the shell, type quit() or use the <Ctrl-C> shortcut.


*** 


Source: https://docs.mongodb.com/manual/data-modeling/



Data Models

Data in MongoDB has a flexible schemaCollections do not enforce document structure. This flexibility gives you data-modeling choices to match your application and its performance requirements.
Data Modeling Introduction
An introduction to data modeling in MongoDB.
Document Validation
MongoDB provides the capability to validate documents during updates and insertions.
Data Modeling Concepts
The core documentation detailing the decisions you must make when determining a data model, and discussing considerations that should be taken into account.
Data Model Examples and Patterns
Examples of possible data models that you can use to structure your MongoDB documents.
Data Model Reference
Reference material for data modeling for developers of MongoDB applications.



**** 


No comments:

Post a Comment