我遇到了 typegoose 的错误。我有一个名为的模型SP
,我必须在其属性上创建 2dsphere 索引,名为geoLocation
我尝试过 typegoose 装饰器@index
,但它无法正常工作,即使它没有抛出任何错误,我不知道发生了什么以及 typegoose 如何处理它。有没有人给我解决方案。
代码:
import { Prop, index, modelOptions, Severity } from '@typegoose/typegoose';
import { BaseModel } from '../base.model';
import { Factory } from 'nestjs-seeder';
export enum SPStatus {
INAVTIVE = "INAVTIVE",
ACTIVE = "ACTIVE",
}
@modelOptions({ options: { allowMixed: Severity.ALLOW } })
@index({ geoLocation: '2dsphere' }, {})
export class SP extends BaseModel{
@Factory(faker => faker.company.companyName())
@Prop({ required: true, index: true, text: true })
businessName : string
@Factory(faker => {
let data = {
type : "Point",
coordinates:[Number(faker.address.longitude()), Number(faker.address.latitude())]
}
console.log(data);
return data;
})
@Prop({ required: false })
geoLocation: {
type: string,
coordinates: [number]
}
}