MongoDB get first and last document in aggregate query
<p>How can I get first and last document based on <code>time</code> field.
I can use <code>$group</code> and get <code>$first</code> and <code>$last</code> document, but I don't need grouping here, just get first and last full document. Maybe I could use <code>slice</code>? This query doesn't work:</p>

<pre><code>{
  "aggregate": "353469045637980_data",
  "pipeline": [
    {
      "$match": {
        "$and": [
          {
            "time": {
              "$gte": 1461369600
            }
          },
          {
            "time": {
              "$lt": 1461456000
            }
          }
        ]
      }
    },
    {
      "$project": {
        "first": {
          "$slice": 1
        },
        "last": {
          "$slice": -1
        }
      }
    }
  ]
}
</code></pre>