MongoDB Spring-data-mongodb integration (Win10 x64) Chapter 1,

Source: Internet
Author: User

MongoDB Spring-data-mongodb integration (Win10 x64) Chapter 1,

This is the first chapter of the MongoDB series and will be updated continuously by the author.

1. Download

Https://www.mongodb.com/download-center#community

2. installation and configuration

For any installation difficulties, click here to view the official guide

Execute the msi file and follow the prompts to install it.

After the installation is complete, find the MongoDB installation path. The default value is

 

C:\ProgramFiles\MongoDB\Server\3.4\

Create a data folder in this directory, that is

 

C:\ProgramFiles\MongoDB\Server\3.4\data

Open PowerShell, move to the bin directory, and type:

./mongod --dbpath C:\ProgramFiles\MongoDB\Server\3.4\data

Shows the successful startup:

3. Start Using

In case of usage difficulties, click the link: official command line guide official addition, deletion, query, and modification examples

Create a PowerShell window, move to the MongoDB \ Server \ 3.4 \ bin directory, and type:

./mongo

After establishing a connection with MongoDB running on the local machine, view all databases on the local machine, and type:

show dbs

Next, use the test Library as an example, and type:

use test

Use the insertOne function provided by MongoDB to insert three data entries to the test database:

db.collection.insertOne({"a": 3})db.collection.insertOne({"c": 4})db.collection.insertOne({"f": 5})

Call the find function to view the inserted data:

db.collection.find()

Here we will briefly introduce the storage of data (documents) and storage of files (images and videos), which will be used by GridFS.

4. GridFS

GridFS is a file storage specification, and MongoDB is an implementation of the GridFS specification, used to store a large number of small files.

The GridFS specification specifies a standard for splitting files. Each file will save a metadata object in the file collection object. One or more chunk block objects can be combined and saved in one chunk block set.

GridFS uses two tables to store data:

  • Files-contains metadata objects
  • Chunks-binary block containing other related information

To name multiple GridFS as a single database, files and blocks have a prefix. By default, the prefix is fs. Therefore, any default GridFS storage will include the namespace fs. files and fs. chunks.

The test database is still used here. The author has uploaded some documents for testing. Type:

show collections

In addition to the collection generated by inserting test data, there are also fs. chunks and fs. files collections. Type:

db.fs.files.find()

It can be seen that files stores the descriptions of files, the "_ id", "chuckSize", "uploadDate", and "md5" fields are automatically generated by MongoDB (if they are not modified in the program ).

Let's take a look at fs. chunks:

db.fs.chunks.find()

A large number of characters in the figure are the results of MongoDB reading files as binary streams for storage.

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.