'MongoDB: either as writer or director list each person only once even if they have credits in both categories

In my Crew collection there are writers and directors whereas they have different movies. But I want to list only one name for each, even a one person is directed or/and written the movie, I want to show it only once. And I should filter the ones that has "tt0071853"

example of a collection:


{ "_id" : "nm0000847", "name" : "Theda Bara", "birthYear" : 1885, "deathYear" : 1955, "directed" : [ "tt0071853","tt5943392", "tt5988204" ], "written" : [ "tt0009637" ], "missingDate" : true }

{ "_id" : "nm0000858", "name" : "John Barrymore", "birthYear" : 1882, "deathYear" : 1942, "directed" : [ "tt0071853", "tt8568790", "tt8632012" ], "written" : [ "tt0017667" ], "missingDate" : true }

{ "_id" : "nm0000859", "name" : "Lionel Barrymore", "birthYear" : 1878, "deathYear" : 1954, "directed" : [ "tt0071853","tt0008183", "tt0019988", "tt0020126", "tt0020534", "tt0021292", "tt0021307", "tt0021345", "tt0021933", "tt0022469" ], "written" : [ "tt0071853","tt0008183" ], "missingDate" : true }

{ "_id" : "nm0000875", "name" : "L. Frank Baum", "birthYear" : 1856, "deathYear" : 1919, "directed" : [ "tt0071853", ], "written" : [ "tt0000679", "tt0004099", "tt0004457", "tt0016544", "tt0032138", "tt0056294", "tt0059920", "tt0060398", "tt0065223", "tt0066801", "tt0067280", "tt0075030", "tt0078504", "tt0084458", "tt0089908", "tt0111641", "tt0120733", "tt0139657", "tt0071853","tt1623205", "tt1988544" ], "missingDate" : true }

{ "_id" : "nm0000927", "name" : "Irving Berlin", "birthYear" : 1888, "deathYear" : 1989, "directed" : [ ], "written" : [ "tt0017433", "tt0021110", "tt0021287", "tt0029345", "tt0029852", "tt0034862", "tt0036430", "tt0038370" ], "missingDate" : true }

{ "_id" : "nm0000923", "name" : "Busby Berkeley", "birthYear" : 1895, "deathYear" : 1976, "directed" : [ "tt0024549", "tt0025028", "tt0026139", "tt0026421", "tt0026512", "tt0028257", "tt0028305", "tt0028939", "tt0029010", "tt0030007", "tt0030171", "tt0030433", "tt0031066", "tt0031298", "tt0032022", "tt0032487", "tt0033110", "tt0033400", "tt0033803", "tt0034415", "tt0034485", "tt0034746", "tt0035703", "tt0035916", "tt0035942", "tt0038415", "tt0040745", "tt0041944", "tt0042200", "tt0043350" ], "written" : [ ], "missingDate" : true }


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source