如何实施“等于”对于MongoDB的接口?
export interface IHealthPlanCard {
_id: string,
statusId: string;
}
const cards: IHealthPlanCard[] = await healthPlanCardsCollection.find(...)
cards.filter(card => card.statusId.equals(cardStatusId))
属性'等于''
在这种情况下,它向我显示了错误: 写这样的东西:
export interface IHealthPlanCard {
_id: string,
statusId: string | eqauls;
}
export interface IHealthPlanCard {
_id: string,
statusId: string;
}
const cards: IHealthPlanCard[] = await healthPlanCardsCollection.find(...)
cards.filter(card => card.statusId.equals(cardStatusId))
In that case it shows me error: Property 'equals' does not exist on type 'string'.ts(2339)
I can't write something like that:
export interface IHealthPlanCard {
_id: string,
statusId: string | eqauls;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您使用的是mongodb(或mongoose)并处理objectids,则应始终使用
ObjectId
type而不是String
:这将唯一如果将模式定义为使用
ObjectID
而不是String
。现在,您的objectIds将具有
.equals()
方法。If you are using MongoDB (or mongoose) and dealing with ObjectIds, you should always use the
ObjectId
type instead ofstring
:This will only work if you defined your schema to use
ObjectId
instead ofstring
.Now your ObjectIds will have the
.equals()
method.