You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am trying these 2 ways to create a 2dsphere index on a collection, but both failed. Both created a regular index.
The first creates a compound index and the second creates a regular index.
import (
"context""github.com/paulmach/orb/geojson""github.com/qiniu/qmgo/options""go.mongodb.org/mongo-driver/bson""go.mongodb.org/mongo-driver/mongo"
)
// StoreGeoJSONCollection is the collection name for the store geojson modelconstStoreGeoJSONCollection="stores_geojson"// StoreGeoJSON represents the store geojson modeltypeStoreGeoJSONstruct {
Model`bson:",inline"`StoreIdObjectID`bson:"store_id" json:"store_id" validate:"required"`StoreNamestring`bson:"store_name" json:"store_name" validate:"required"`Titlestring`bson:"title" json:"title" validate:"required"`Geojson*geojson.FeatureCollection`bson:"geojson" json:"geojson" validate:"required"`DeliveryFeefloat64`bson:"delivery_fee" json:"delivery_fee"`MinimumOrderValuefloat64`bson:"minimum_order_value" json:"minimum_order_value"`DeliveryProductId*string`bson:"delivery_product_id" json:"delivery_product_id"`
}
// CollectionName returns the collection name for the store geojson modelfunc (StoreGeoJSON) CollectionName() string {
returnStoreGeoJSONCollection
}
// Indexes returns the indexes for the store geojson modelfunc (StoreGeoJSON) Indexes() []options.IndexModel {
return []options.IndexModel{
{
Key: []string{"geojson.features.geometry", "2dsphere"},
IndexOptions: Index().SetSphereVersion(3),
},
{
Key: []string{"geojson.features.geometry"},
IndexOptions: Index().SetSphereVersion(3),
},
}
}
Indexes Screenshot
Please share the correct way to create 2dsphere indexes using qmgo.
The text was updated successfully, but these errors were encountered:
I am trying these 2 ways to create a
2dsphere
index on a collection, but both failed. Both created a regular index.The first creates a compound index and the second creates a regular index.
Indexes Screenshot
The text was updated successfully, but these errors were encountered: