Install a tutorial using MongoDB on Mac OS _mongodb

Source: Internet
Author: User
Tags install mongodb mongodb mongodb collection mongodb find numeric value reserved mongodump mongorestore

Concept
MongoDB is a cross-platform, document-oriented database that delivers high performance, high availability, and scalability. MongoDB work in the collection and document concept.

What is NoSQL?
NOSQL, the full name is not just SQL, refers to the database of non relational type. The next generation database mainly solves several main points: non-relational, distributed, open source, level scalable. The original purpose was for large-scale Web applications, which began in the early 2009, with typical features such as free mode, support for easy replication, simple APIs, final consistency (non-acid), bulk data, and so on. NoSQL is the most used Key-value storage, of course, there are other document-type, column storage, graph database, XML database and so on.

Why to use MongoDB
the form of JSON-style files, document-oriented storage: data storage

    • indexable for any attribute
    • Replication and high Availability
    • Automatic slicing
    • A rich query
    • Quick in-place updates

Professional technical support of MongoDB
where should I use MongoDB?

    • Large data
    • Content Management and delivery
    • Mobile and social infrastructure
    • User Data Management
    • Data platform

MongoDB is a product between relational database and non relational database, and is the most powerful and relational database in the relational database. The data structure he supports is very loose and is a JSON-like Bson format, so you can store more complex data types.

The basic usage is to store JSON data, which is good for JavaScript programs. Its characteristics are as follows:

1. No concept of table structure, each record can have a completely different structure
2. Fast and convenient business development
3. SQL database needs to define table structure prior to use
Install MongoDB under Mac
first, in the browser or Third-party tools to download
Current version of the download address: http://downloads.mongodb.org/osx/mongodb-osx-x86_64-2.4.6.tgz

Or the second, open the terminal and use the following command line to download:

Curl http://downloads.mongodb.org/osx/mongodb-osx-x86_64-2.4.6.tgz > Mongodb.tgz

After the installation is successful, the "Mongod" command starts the MONGO database. Enter http://127.0.0.1:28017 in the browser if the MONGO database information is displayed correctly, the startup is successful.

After the successful interface:

Installation steps
1. First in the terminal input LS, listing directories, find your MongoDB file, to tgz the end of the

2. Open the terminal, input TAR-ZXVF mongodb-osx-x86_64-2.4.6, of course, the respective version number of their corresponding correct AH.

3. Move the extracted installation files to your preferred location:

Mv-n ~/downloads/mongodb-osx-x86_64-2.4.6 ~/applications/mongodb/

My extract directory is downloads, the default move to Applications MongoDB folder is invisible

4, in the root directory/under the creation of data/db directory, for the placement of MONGODB data, and to set permissions on the directory

sudo mkdir-p/data/db
sudo chown-r trigkit4/data

5. Start MongoDB Service

Open the terminal, enter the CD Applications/mongodb/bin, enter the entry./mongod

6. Open another terminal, enter Applications/mongodb/bin, return, enter./mongo

Document
documents are the core concepts of MONGODB, and multiple keys and their associated values are placed together in an orderly manner. In JS, the document is represented as an object:

{"greenting": "hello,world!"}

This object has only one key "greeting" and its corresponding value "hello,world!"

The key of the document is a string, with a few exceptions, the key can use any UTF-8 character:

-The key cannot contain a (null character). This character is used to indicate the end of the key
-. and $ have special meaning that can only be used in certain circumstances and are usually reserved
-The keys at the beginning of the underlined "_" are reserved, though not strictly
MongoDB is not only sensitive to types, but also case sensitive, and MongoDB documents cannot have duplicate keys, such as the following documents are illegal:

{"Greeting": "hello,world!", "greeting": "hello,mongodb!"}

Collection
A collection is a set of documents. If the document in MongoDB resembles a row in a relational database, the collection is like a table.

No mode
the collection is modeless. This means that the documents within the collection can be of various kinds, such as the following two documents can exist in the same set:

{"Greeting": "hello,world!"}
{' foo ': 5}

Named
we can use names to mark the collection. The collection name can be a UTF-8 condition that satisfies the following conditions

-the collection name cannot be an empty string "".
-The collection name cannot contain a "character" (Null character)
-the collection name cannot be "system." Beginning, this is the prefix reserved for the system collection
-the user-created collection name cannot contain reserved characters $
Child Collections
one of the conventions of organizing collections is to use the "." A subset of characters divided by a namespace.

Basic operations in the shell
4 basic actions are used to view data in the shell: Create, read, update, and delete (CRUD)

Database
multiple documents in the MongoDB form a collection, and more than one collection can form a database. A MongoDB instance can host multiple databases, and the database name can be any UTF-8 string that satisfies the following criteria

-cannot be an empty string ("")
-Cannot contain ' (space) 、.、 $,/, \ and (null characters)
-should be all lowercase
-Up to 64 bytes
data type
MongoDB supports a list of many data types given below:

    • String: This is the most commonly used data type to store data. The string in MongoDB must be a valid UTF-8.
    • Integer: This type is used to store a numeric value. The integer can be either 32-bit or 64-bit, depending on your server.
    • Boolean: This type is used to store a Boolean value (True/false).
    • Double: This type is used to store floating-point values.
    • Min/max keys: This type is used to compare the lowest and highest values of Bson elements.
    • Arrays: Stores a key with an array or list of this type or multiple values.
    • Timestamp: Time stamp. This can be handy when recording files that have been modified or added.
    • Object: This data type is used for embedded files.
    • Null: This type is used to store a null value.
    • Symbol: This data type is used for the same string, but it is usually used in languages reserved for a particular type of symbol.
    • Date: This data type is used to store the UNIX time format for the current date or time. You can specify your own date and time, date and year, month, day to create the object.
    • Object ID: This data type is used to store the ID of the document.
    • Binary: This data type is used to store binary data.
    • Code: This data type is used to store JavaScript code in the document.
    • Regular expression: This data type is used to store regular expressions

Basic commands for MongoDB

Use command
MongoDB use database_name is used to create a database. This command will create a new database, and if it does not exist, it will return the existing database.

Dropdatabase () method
The MongoDB db.dropdatabase () command is used to delete an existing database.
The basic syntax for the dropdatabase () command is as follows:

Db.dropdatabase ()
Drop () method
The MongoDB Db.collection.drop () is used to delete a collection from the database.

Insert () method
To insert data into the MongoDB collection, you need to use the MongoDB Insert () or Save () method.

Find () method
To query the collection data from the MongoDB, you need to use the MongoDB find () method.

Pretty () method
The results are shown in a format that can be used with the pretty () method.

Limit () method
To limit the records in MongoDB, you need to use the limit () method. The limit () method accepts a numeric parameter, which is the number of documents to display.
Grammar:

The basic syntax for the limit () method is as follows

>db. Collection_name.find (). Limit (number) 

MongoDB Data dumps
to create a database in a backup MongoDB, you should use the Mongodump command.
The basic syntax for the Mongodump command is as follows:

>mongodump

Recover data
Restore the backup data using the MongoDB mongorerstore command. This command restores all data from the backup directory.
Grammar:

Basic syntax for Mongorestore commands

>mongorestore

The rest of the method or order you can go online search, here is not to repeat the AH.

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.