This is my organisation Collection, which has certain opportunitystatus as an array.
{
"_id" : ObjectId("5c756b4ea5a8cd1b0d3fbfe7"),
"opportunitystatus" : [
{
"name" : "Call Scheduled"
},
{
"name" : "In-Process"
},
{
"name" : "Review Proposal"
},
]
"companyname" : "XYZZZ",
"creation_dt" : ISODate("2019-02-26T16:37:34.115Z"),
}
I do have another collection of leads which has an array of opportunities,
Lead 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"),
}
Lead 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"),
}
Now, i want to write a query on given organization so that i can get all the opportunity status with their respective opportunities
"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")
}
]
},