Database

[{title:"book one title",categories:["Thriller"]},{title:"book TWO title",categories:["Adventure","Action"]},{title:"book 3 title",categories:["Action","Musical","Animated"]},{title:"fourth book",/** both of these are duplicate categories*/categories:["Thriller","Musical"]}]

Query

db.collection.aggregate([{"$group":{"_id":null,/** this is the only line I changed*/"categories1":{"$addToSet":{"$arrayElemAt":["$categories",0]}},"categories2":{"$addToSet":{"$arrayElemAt":["$categories",1]}}}},{"$project":{_id:0}}])

Result