MongoDB Index 3

Source: Internet
Author: User

1.name Properties

When the new index is created, you can see the property value of name,

When a new index is multiple attributes, the name is separated by _, and the name value is up to 128 bytes long, which can be renamed when a new index is created with multiple property values.

Direct index names are followed by the Name property names, which can also be used to delete indexes directly using name.

2.db.tablename.ensureindex ({inserted index},{unique:true/false})

Creates a new index that specifies a unique.

Insert data display succeeds when inserting data again with the previously inserted data m n, error.

3. Sparse-----Sparse

Sparse example: There is an M index, the newly inserted data if it is N:1, then M will also create an index for this data, is null, when the sparsity is specified, M will not create an index for this data.

Db.tableName.ensureIndex ({inserted index},{sparse:true/false)}

Mongdb default is not sparse, that is, the non-existent field is created index.

Benefit: Do not create indexes for nonexistent fields, reduce occupancy, increase speed!

Introduce a thing first

{ field: { $exists: <boolean> } }

True to find M data FALSE to find data without M

You cannot find a record on a sparse index that does not exist on this field, forcing the specified index. Hint (index name)

Forces the specified index to be empty after the search results.

4. Location Index

Category: 1.2D index filed by points on a plane

2.2Dsphere index filed by point on spherical surface

Method: 1. Find points within a certain distance of a certain point

2. Find points that are contained within a region

5.2D Index

Db.tableName.ensureIndex ({w:2d})

Use latitude to indicate location "longitude, latitude"

Range of values -180< longitude <180-90< latitude <90

The inserted point should be in the range, or an unpredictable error will occur.

Query method: 1. $near query: Query According to a point the nearest point result is 100 (regardless of full condition)

2. $geoWithin query, query the point of a shape

Mindistance not supported

The representation of a shape:

1. $box: Rectangle

{$box: [[<x1>,<y1>],<x2>,<y2>]} Indicates that the first is the left boundary and the second right boundary

2. Round $center

{$center: [[<x1>,<y1>],r]} indicates

3. Polygon $polygon

{$polygon: [[<x1>,<y1>],[<x2>,<y2>],[<x3>,<y3>]}

MongoDB Index 3

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.