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