用猫鼬通过查询写一个组

时间:2019-04-09 10:44:42

标签: node.js mongodb mongoose

这是我的组织集合,它具有某些机会状态作为数组。

{
    "_id" : ObjectId("5c756b4ea5a8cd1b0d3fbfe7"),
    "opportunitystatus" : [ 
        {
            "name" : "Call Scheduled"
        }, 
        {
            "name" : "In-Process"
        }, 
        {
            "name" : "Review Proposal"
        }, 

     ]
    "companyname" : "XYZZZ",
    "creation_dt" : ISODate("2019-02-26T16:37:34.115Z"),
}

我确实有另一个潜在客户集合,其中包含很多机会,
领先1

{
    "_id" : ObjectId("5cab60e23512066ccac03bdf"),
    "organization_id" : ObjectId("5c756b4ea5a8cd1b0d3fbfe7"),
    "companyname" : "Another Health Plans Inc.",
    "opportunities" : [ 
        {
            "_id" : ObjectId("5cac4efe3f8e9d28221a7d66"),
            "confidence" : 10,
            "status" : "Call Scheduled",
            "valuevalidity" : "One time",
            "estimatedclose" : ISODate("2019-12-31T00:00:00.000Z"),
            "date" : ISODate("2019-04-09T07:51:26.977Z")
        }, 
        {
            "_id" : ObjectId("5cac4f2b3f8e9d28221a7d68"),
            "confidence" : 10,
            "status" : "Reviewing Proposal",
            "estimatedclose" : Date(-23890291200000),
            "date" : ISODate("2019-04-09T07:52:11.149Z")
        }
    ],
    "creation_dt" : ISODate("2019-04-08T14:55:30.921Z"),
    "updated_dt" : ISODate("2019-04-08T14:55:30.921Z"),
}


领先2

{
    "_id" : ObjectId("5cab60e23512066ccac03bdf"),
    "organization_id" : ObjectId("5c756b4ea5a8cd1b0d3fbfe7"),
    "companyname" : "Health Plans Inc.",
    "opportunities" : [ 
        {
            "_id" : ObjectId("5cac4efe3f8e9d28221a7d33"),
            "confidence" : 10,
            "status" : "Reviewing Proposal",
            "valuevalidity" : "One time",
            "estimatedclose" : ISODate("2019-12-31T00:00:00.000Z"),
            "date" : ISODate("2019-04-09T07:51:26.977Z")
        }        ],
    "creation_dt" : ISODate("2019-04-08T14:55:30.921Z"),
    "updated_dt" : ISODate("2019-04-08T14:55:30.921Z"),
}

现在,我想对给定的组织写一个查询,以便我可以获取所有机会状态及其各自的机会

    "opportunitystatus" : [ 
        {
            "name" : "Call Scheduled",
            opportunities:[
               {
                "_id" : ObjectId("5cac4efe3f8e9d28221a7d66"),
                "confidence" : 10,
                "status" : "Call Scheduled",
                "valuevalidity" : "One time",
                "estimatedclose" : ISODate("2019-12-31T00:00:00.000Z"),
                "date" : ISODate("2019-04-09T07:51:26.977Z")
             }, 
           ]
        }, 
        {
            "name" : "In-Process"
        }, 
        {
          "name" : "Review Proposal",
          opportunities:[
           {
               "_id" : ObjectId("5cac4f2b3f8e9d28221a7d68"),
                "confidence" : 10,
                "status" : "Reviewing Proposal",
                "estimatedclose" : Date(-23890291200000),
                "date" : ISODate("2019-04-09T07:52:11.149Z")
            },
            {
                "_id" : ObjectId("5cac4efe3f8e9d28221a7d33"),
                "confidence" : 10,
                "status" : "Reviewing Proposal",
                "valuevalidity" : "One time",
                "estimatedclose" : ISODate("2019-12-31T00:00:00.000Z"),
                "date" : ISODate("2019-04-09T07:51:26.977Z")
            } 

         ]
        }, 

0 个答案:

没有答案