0
votes

I have 2 collections (collection1 and collection 2) into one DB into mongoDB. into both collections there is a field called "DeviceId". I want to know,how could I compare these two collections based on "DeviceId"? I want to see which DeviceId into collection1 does not exist into collection2 and then I want copy it into collection2.

This is document schema:

{
"_id" : UUID("236073ce-a583-4df4-ba7d-bda6db186d10"),
"Lat" : "",
"Lng" : "",
"CreationDateTime" : ISODate("2017-09-26T06:39:29.105Z"),
"DeviceId" : "89984320001499681815",
"Topic" : "",
"UserId" : UUID("bca0db12-2246-49a5-8703-b03fee45e50f"),
"UserName" : "",
"Data" : {
    "AppVersion" : "",
    "AppName" : ""
},
"DeviceIdId" : ,
"FirstName" : " ",
"LastName" : "",
"AllowDomains" : "",
"JobLocationName" : ""
}

This schema is common between two collections.

1

1 Answers

0
votes

You can use $lookup:

Maybe this guide can be helpfull: operator/aggregation/lookup/