position generates out of bounds geo2d coordinates
Closed this issue · 0 comments
idc77 commented
"location": {
"type": "object",
"objectContent": {
"type": {
"type": "constant",
"constVal": "Point"
},
"coordinates": {
"type": "position"
}
}
},
err
Error: (Location16755) Index build failed: c07cf731-43b6-4371-80e0-f29ef058cc90: Collection iloveu.profile ( 7783600a-51ea-4165-8acd-9f856a8b26eb ) :: caused by :: Can't extract geo keys: { _id: ObjectId('62215774a8f4a4641a612445'), username: "Idell", description: ""Vegan Thundercats Yuccie vinegar DIY Yuccie." - Devan Gerlach", subject_id: "04d5cce3-f1c6-4462-a605-58d06a2a8e94", seeking: "", location: { type: "Point", coordinates: [ 36.50425432207004, 110.2707559292275 ] }, identity: "m", gender: "m", birthdate: "1952/4/20" } longitude/latitude is out of bounds, lng: 36.5043 lat: 110.271
db := client.Database(config.Database)
indexOpts := mopts.CreateIndexes().SetMaxTime(config.DefaultTimeout)
// Index to location 2dsphere type.
pointIndexModel := mongo.IndexModel{
Options: mopts.Index(),
Keys: bsonx.MDoc{"location": bsonx.String("2dsphere")},
}
pointIndexes := db.Collection("profile").Indexes()
_, e = pointIndexes.CreateOne(ctx, pointIndexModel, indexOpts)
if e != nil {
return e
}
Either a new type should be added, geo2d, since you're generating data for mongodb, which uses geo2d...
or an option should be added to switch long,lat ordering
I would change it locally but I have no idea what
g.buffer.Write(float64Bytes(90 * float64(i+1) * (2*(float64(g.pcg64.Random())/(1<<64)) - 1)))
means...
Now I get it you push the y value then the x value because it's just 2*(1-90)
smh
func (g *positionGenerator) EncodeValue() {
current := g.buffer.Len()
g.buffer.Reserve()
// val 1 (0-180)
g.buffer.WriteSingleByte(byte(bson.TypeDouble))
g.buffer.WriteSingleByte(indexesBytes[0])
g.buffer.WriteSingleByte(byte(0))
g.buffer.Write(float64Bytes(90 * float64(2) * (2*(float64(g.pcg64.Random())/(1<<64)) - 1)))
// val 2 (0-90)
g.buffer.WriteSingleByte(byte(bson.TypeDouble))
g.buffer.WriteSingleByte(indexesBytes[1])
g.buffer.WriteSingleByte(byte(0))
g.buffer.Write(float64Bytes(90 * float64(1) * (2*(float64(g.pcg64.Random())/(1<<64)) - 1)))
g.buffer.WriteSingleByte(byte(0))
g.buffer.WriteAt(current, int32Bytes(int32(g.buffer.Len()-current)))
}