第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機(jī)立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

無法通過 2sphere 找到元素

無法通過 2sphere 找到元素

Go
森林海 2023-06-05 19:40:47
我來是因?yàn)槲倚枰獙?shí)現(xiàn)地理計算,但是,它不起作用。我目前正在使用這個包globalsign/mgo從文檔中我們有這個:db.<collection>.find( { <location field> :        { $near :            { $geometry :                { type : "Point" ,                     coordinates : [ <longitude> , <latitude> ] } ,                     $maxDistance : <distance in meters>,                }             }       }  查詢2dsphere索引:https://docs.mongodb.com/manual/tutorial/query-a-2dsphere-index/ 2dsphere索引:https://docs.mongodb.com/manual/core/2dsphere/所以我有以下內(nèi)容:import (    "github.com/globalsign/mgo/bson"    "shared/models"    "time")type Address struct {    ID                 *bson.ObjectId `protobuf:"bytes,1,opt,name=id,proto3" json:"_id,omitempty" bson:"_id"`    IsArchived         bool           `protobuf:"varint,2,opt,name=IsArchived,proto3" json:"is_archived,omitempty" bson:"is_archived"`    CreatedAt          time.Time      `protobuf:"varint,3,opt,name=CreatedAt,proto3" json:"created_at,omitempty" bson:"created_at"`    UpdatedAt          time.Time      `protobuf:"varint,4,opt,name=UpdatedAt,proto3" json:"update_at,omitempty" bson:"updated_at"`    PlaceID            *bson.ObjectId `protobuf:"bytes,5,opt,name=PlaceID,proto3" json:"place_id,omitempty" bson:"place_id"`    CountryCode        string         `protobuf:"bytes,6,opt,name=CountryCode,proto3" json:"country_code,omitempty" bson:"country_code,omitempty"`    AdministrativeArea string         `protobuf:"bytes,7,opt,name=AdministrativeArea,proto3" json:"administrative_area,omitempty" bson:"administrative_area,omitempty"`由此,我收到以下錯誤:“錯誤處理查詢:ns=DBNAME.addressDocumentTree:GEONEAR field=location maxdist=5e+06 isNearSphere=0\nSort:{}\nProj:{}\n 規(guī)劃器返回錯誤:無法找到 $geoNear 查詢的索引”我在程序初始化時確保我的索引
查看完整描述

1 回答

?
慕村9548890

TA貢獻(xiàn)1884條經(jīng)驗(yàn) 獲得超4個贊

終于找到了問題..實(shí)際上,我沒有以正確的方式創(chuàng)建索引..


// EnsureIndex force ids to be unique

func EnsureAddressIndex(session *mgo.Session) error {


    _session := session.Copy()

    defer _session.Close()


    c := _session.DB(constants.DBName).C(addressDocument)

    // Might be needed one day

    pIndex := mgo.Index{

        Key:  []string{"$2dsphere:location"},

        Bits: 26,

    }

    err := c.EnsureIndex(pIndex)

    if err != nil {

        return err

    }


    return nil

}

在索引聲明中,我有以下行:


pIndex := mgo.Index{

    Key:  []string{"location:2dsphere"},

    Bits: 26,

}

但正確的寫法是


pIndex := mgo.Index{

    Key:  []string{"$2dsphere:location"},

    Bits: 26,

}

希望能幫助到你 !


查看完整回答
反對 回復(fù) 2023-06-05
  • 1 回答
  • 0 關(guān)注
  • 119 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號