回送仅从对象的属性数组中获取一个对象

时间:2019-06-23 02:58:49

标签: arrays mongodb loopback

我正在使用回送和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"
}

0 个答案:

没有答案
相关问题