Question: I have a container with position:relative and three children
with position:absolute.

HTML

```
<div class="container">
    <div>left</div>
    <div>middle</div>
    <div>right</div>
</div>

```

CSS

```
div{
    border:1px solid;
}

.container{
    height:200px;
    position:relative;
}

.container > div{
    height:190px;
    position:absolute;
}

.container > :nth-child(1){
    background:red;
    left:0;    
}

.container > :nth-child(2){
   //background:green;
   margin:auto;
   left:0;
   right:0;
}

.container > :nth-child(3){
    background:blue;
    right:0;
}

```

<http://jsfiddle.net/7xqwrtq2/>

The children are positioned in this order: left, center and right.

How can I prevent the centered div from taking all remaining width?

I want it to be like the others where the width is adjusted to the
content. I don't want to set a fixed width neither.

Thanks in advance.

Answer: 
For people that ends up here looking for a solution to transform an array to an object using aggregation in a more recent version of MongoDB:

MongoDB 3.4.4 introduced [$arrayToObject](https://docs.mongodb.com/manual/reference/operator/aggregation/arrayToObject/)

You have to [$map](https://docs.mongodb.com/manual/reference/operator/aggregation/map/) `years`

```
  {
    $set: {
      years: {
        $map: {
          input: "$years",
          as: "year",
          in: [
            "$$year.year",
            "$$year.avgInstructor"
          ]
        }
      }
    }
  }

```

to be like this

```js
{
  "_id" : "ENVD",
  "years": [
    ["2013", 5.144999999999998],
    ["2012", 5.194436090225564]
  ]
}

```

then use [$arrayToObject](https://docs.mongodb.com/manual/reference/operator/aggregation/arrayToObject/)

```
  {
    $set: {
      years: {
        $arrayToObject: "$years"
      }
    }
  }

```

Or combine the two steps together

```
  {
    $set: {
      years: {
        $arrayToObject: {
          $map: {
            input: "$years",
            as: "year",
            in: [
              "$$year.year",
              "$$year.avgInstructor"
            ]
          }
        }
      }
    }
  }

```
A Possible answer ...

1. Unwind first
2. project to make it a little easier to handle
3. Sort on \_id and then on year
4. group by \_id to pickup the first and the last value
5. final projection to get subtracted value

```
db.coll.aggregate ( [

        { "$unwind" : "$years"  } ,

        { $project : { "year" : "$years.year", "avgInstructor" : "$years.avgInstructor"  } },

        { $sort : { "_id" : 1, "year" : 1 } },

        { $group : { "_id" : "$_id", "val_min" : { $first : "$avgInstructor"  },  "val_max" : { $last : "$avgInstructor" } } },

        { $project : { "diff" : { $subtract : [ "$val_min", "$val_max" ] }  } }

] )

```