compare two collection in mongodb
<p>I have two different collection book and music in JSON .First I give a book collection example:</p>

<pre><code>{
    "_id" : ObjectId("b1"),
    "author" : [
        "Mary",
    ],
    "title" : "Book1",
}
{
        "_id" : ObjectId("b2"),
        "author" : [
            "Joe",
            "Tony",
            "Mary"
        ],
        "title" : "Book2",
}
{
            "_id" : ObjectId("b3"),
            "author" : [
                "Joe",
                "Mary"
            ],
            "title" : "Book3",
}
.......
</code></pre>

<p>Mary writes 3 books, Joe write 2 books, Tony writes 1 book. Second I give a music collection example:</p>

<pre><code> {
        "_id" : ObjectId("m1"),
        "author" : [
            "Tony"
        ],
        "title" : "Music1",
    }
    {
            "_id" : ObjectId("m2"),
            "author" : [
                "Joe",
                "Tony"
            ],
            "title" : "Music2",
    }
    .......
</code></pre>

<p>Tony has 2 musics, Joe has 1 music, Mary has 0 music.</p>

<p>I hope to get the number of authors who write more books than music.</p>

<p>Thus, Mary(3 > 0) and Joe(2 > 1) should take into consideration, but not Tony(1 &lt; 2). Thus the final result should be 2(Mary and Joe).</p>

<p>I write down following code, but don't know how to compare:</p>

<pre><code>db.book.aggregate([ 
     { $project:{ _id:0, author:1}},
     { $unwind:"$author" },     
     {$group:{_id:"$author", count:{$sum:1}}}  
     ]
     )

db.music.aggregate([ 
     { $project:{ _id:0, author:1}},
     { $unwind:"$author" },     
     {$group:{_id:"$author", count:{$sum:1}}}  
     ]
     )
</code></pre>

<p>Is it so far right? How to do the following comparison? Thanks.</p>