strongloop/loopback-connector-mongodb — pull request #72 by amenadiel (2014-12-19 12:04:55+00:00)
Title: Allows optional use of $set  and $addToSet

At this point, loopback's mongodb connector implementation of updateOrCreate has the [$set](http://docs.mongodb.org/manual/reference/operator/update/set/) operator hardcoded. For example, given the Product

```
{id:12345, name:'oldname','price':100, 'historicprice':[90]}
```
the following operation
```
Model.updateOrCreate({
id:12345,
name:'newname'
}, function(err,cb));
```
would result in an updated model with all the original properties, but whose name is now 'newname'.

```
{id:12345, name:'newname','price':100, 'historicprice':[90]};
```

With this pull request, you can still use the current method (this is, passing updateOrCreate an object with the properties you want to update) but you can also refine the syntax to specify what do you want to update and what do you want to append to an array, using [$addToSet](http://docs.mongodb.org/manual/reference/operator/update/addToSet/). For example

```
Model.updateOrCreate({
id:12345,
$set: {name:'newname'},
$addToSet: {historicprice:95},
}, function(err,cb));
```

will $set a new name, and will append a new value to 'historicprice' instead of overwriting the existing one.

```
{id:12345, name:'newname','price':100, 'historicprice':[90,95]};
```

This is part of an ongoing effort to implement more native MongoDB functions to properly replace existing apps that use lower level libraries.