db.runCommand( {create :
"CreditorMappings",
viewOn : "yggdrasilconfiguration",
pipeline : [
{$unwind : '$CreditorsMapping'},
{$project : {
_id : 1,
OrganizationId : '$OrganizationId',
PrimaryId : '$CreditorsMapping.PrimaryId',
CreditorId : '$CreditorsMapping.CreditorId',
ApplicationId : '$CreditorsMapping.ApplicationId'
},
{$match : {PrimaryId : {$ne : ""}}}
]
})
db.getCollection('yggdrasilconfiguration').aggregate([
{$unwind : '$CreditorsMapping'},
{$project : {
_id : 0,
OrganizationId : '$OrganizationId',
ToStringedOrganizationId : '$OrganizationId'.toString(),
StrOrganizationId : '$OrganizationId'.str,
TojsonOrganizationId : tojson('$OrganizationId'),
PrimaryId : '$CreditorsMapping.PrimaryId',
CreditorId : '$CreditorsMapping.CreditorId',
ApplicationId : '$CreditorsMapping.ApplicationId'}
},
{$match : {PrimaryId : {$ne : ""}}}
])
{
"OrganizationId" : ObjectId("542d53fc669a710728349cc8"),
"ToStringedOrganizationId" : ObjectId("542d53fc669a710728349cc8"),
"StrOrganizationId" : undefined,
"TojsonOrganizationId" : "\"$OrganizationId\"",
"PrimaryId" : "915568",
"CreditorId" : "7626",
"ApplicationId" : ObjectId("542e5dca669a7107d8ac1da5")
}
It should be possible to convert the ObjectId’s to strings, but all my attempts have failed.
Hi Olav,
Currently there is no way to convert ObjectId to string format inside the aggregation pipeline. However there’s an open ticket to track this request SERVER-24947, please feel free to upvote/watch for updates.
If it’s possible for your use case, you could perhaps add another field to join the two collections in a format that Apache Drill and PowerBI could read.
Regards,
Wan.