Map-Reduce on `system.profile` collection I have a simple collection posts with a few documents in it. I have set the profiling level to 2 allowing for profiling information to be collected into another collection system.profile. My goal is to use a mapReduce operation to collect information from the command entry grouped via various actors using this simple query:
db.system.profile.mapReduce(
    function()
    {
        emit( this.appName, this.command  );
    },
    function( key, values ) 
    {
        return JSON.stringify(values);
    },
    {
        query: {},
        out  : &quot;command_maps&quot;
    }
)

However, trying this in the REPL yields the following error
2021-05-10T22:09:33.494+0800 E QUERY    [js] Error: map reduce failed:{
    &quot;ok&quot; : 0,
    &quot;errmsg&quot; : &quot;rename failed: { ok: 0.0, errmsg: \&quot;error with source namespace: cannot write to 'test.tmp.mr.system.profile_22'\&quot;, code: 20, codeName: \&quot;IllegalOperation\&quot; }&quot;,
    &quot;code&quot; : 10076,
    &quot;codeName&quot; : &quot;Location10076&quot;
} :
_getErrorWithCode@src/mongo/shell/utils.js:25:13
DBCollection.prototype.mapReduce@src/mongo/shell/collection.js:1145:1
@(shell):1:1

I suspect mongo is trying to temporarily write into the system.profile collection and fails due to it being readonly in a sense. Is there any way to execute this successfully ?
Unfortunately the documents are too large to add here but basically its sort of like this:
DOCUMENT
{ 
   &quot;appName&quot;: &quot;actor1&quot;,     
   &quot;command&quot;: {&quot;find&quot;: {},&quot;ns&quot; : &quot;test.post&quot;&quot;} 
}, 
{  &quot;appName&quot;: &quot;actor2&quot;, 
   &quot;command&quot;: { &quot;find&quot;: {},&quot;ns&quot; : &quot;test.comments&quot;} 
}
{
   &quot;appName&quot;: &quot;actor1&quot;,
   &quot;command&quot;: { &quot;insert&quot;: {},}
}

OUTPUT
{  appName: &quot;actor1&quot;: command_maps: '[{command: &quot;find&quot;}, {command:&quot;query&quot;} ...]' } 
{    appName: &quot;actor2&quot;: command_maps: '[{command: &quot;find&quot;}...]' } 

Version: MongoDB shell version v4.4.5
PS     : mapReduce is working properly on regular collections
So it seems special readWrite privileges are needed to execute mapReduce on system.profile collection. So I got the query to work eventually after checking through:
https://docs.mongodb.com/manual/tutorial/manage-users-and-roles/