Try below code it works for me
@index({ location: '2dsphere' })
export class GPSData extends Typegoose{
@prop({ required: true })
public log_Id!: mongoose.Types.ObjectId;
@ValidateNested({each: true})
@prop({
_id : false
})
readonly location: Location;
}
export class Location extends Typegoose{
@prop()
@IsString({message: " type should be text"})
readonly type: String;
@prop({ required: true })
coordinates: [[Number]];
}
Sample collection (Type can be either one of this "Point", "MultiPoint", "LineString", "MultiLineString", "Polygon", "MultiPolygon", and "GeometryCollection"):
{
"log_Id": "5fbdec08ce02d61fec9a0189",
"location":{
"type":"MultiPoint",
"coordinates":[
[ -73.9580, 40.8003 ],
[ -73.9498, 40.7968 ],
[ -73.9737, 40.7648 ],
[ -73.9814, 40.7681 ]
]
}
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…