$unset specification must be a string or an array

Viewed 1945

I have documents in this structure:

{
   "_id":{
      "$oid":"..."
   },
   "Index":0,
   "KeyIndex":"...",
   "SerialNumber":"...",
   "Tests":[
      {
         "TestName":"...",
         "Status":"...",
         "Steps":[
            {
               "LowLimit":"X",
               "HighLimit":"Y",
               "Result":"Z"
            },
            {
               "LowLimit":"X",
               "HighLimit":"Y",
               "Result":"Z"
            }
         ],
         "Logs":[
            {
               "Type":"Info",
               "Message":"..."
            },
            {
               "Type":"Warning",
               "Message":"..."
            }
         ]
      },
      {
         "TestName":"...",
         "Status":"...",
         "Steps":[
            {
               "LowLimit":"X",
               "HighLimit":"Y",
               "Result":"Z"
            }
         ],
         "Logs":[
            {
               "Type":"Info",
               "Message":"..."
            },
            {
               "Type":"Info",
               "Message":"..."
            }
         ]
      }
   ]
}

As you can see, The Tests property is an array where each object has its own properties, Which 2 of them are arrays them self. I want a stage which removes from all objects which are in the test array the logs property.

The result should be like this:

{
   "_id":{
      "$oid":"..."
   },
   "Index":0,
   "KeyIndex":"...",
   "SerialNumber":"...",
   "Tests":[
      {
         "TestName":"...",
         "Status":"...",
         "Steps":[
            {
               "LowLimit":"X",
               "HighLimit":"Y",
               "Result":"Z"
            },
            {
               "LowLimit":"X",
               "HighLimit":"Y",
               "Result":"Z"
            }
         ]
      },
      {
         "TestName":"...",
         "Status":"...",
         "Steps":[
            {
               "LowLimit":"X",
               "HighLimit":"Y",
               "Result":"Z"
            }
         ]
      }
   ]
}

I am using compass to build the aggregation, I chose $unset stage and tried:

/**
 * fields: The field name(s).
 */
{
  "$Tests.Logs"
}

And:

/**
 * fields: The field name(s).
 */
{
  ["$Tests.Logs"]
}

which says: Stage must be a properly formatted document.

And:

/**
 * fields: The field name(s).
 */
{
  "$Tests.Logs":1
}

which says: $unset specification must be a string or an array .

0 Answers
Related