我正在使用回送和mongodb。现在我有一个Model,它的属性类型之一是对象数组。 mongo中的文档将如下所示:
{
"_id" : "sgG6G9XTvvjj7uxwQ",
"name" : "test",
subscription: [
{
"id":3324,
"state":"Currently",
"type": "A",
"startDate": "Date"
},
{
"id":5465,
"state":"Futuristic",
"type": "A",
"startDate": "Date"
},
{
"id":6575,
"state":"Futuristic",
"type": "A",
"startDate": "Date"
}
]
}
我已经尝试过
await this.clientsRepository.find({ where: { _id:'5d07ee4515741e0fbcfdbad1',
'subscription.state': 'Currently' },fields: { 'subscription.$': true } } })
我确实希望只有一个这样的物体
{
"id":3324,
"state":"Currently",
"type": "A",
"startDate": "Date"
}