【发布时间】:2021-04-13 11:50:57
【问题描述】:
我遇到了 typegoose 的错误。我有一个名为SP 的模型,我必须在其名为geoLocation 的属性上创建2dsphere 索引我尝试了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]
}
}
【问题讨论】:
-
您是在尝试将索引添加到现有集合还是新集合? (如果已有收藏,您是否已经尝试过
Model.syncIndexes?)
标签: node.js mongodb typescript nestjs typegoose