louischatriot/nedb — pull request #109 by eldad87 (2013-12-14 00:31:41+00:00)
Title: Added support for $limit, $skip and $sort aggregation, along with $setAsDefault

__Sort/Skip/Limit Example:__
Current documents:
```
{name: 'john', age: 10}
{name: 'doe', age: 8}
{name: 'eldad', age: 26}
```
Set aggregation:
```remove
db.aggregate({$sort: 'age', $skip: 1, $limit: 1});
```
Find:
```
db.find({}, function(err, docs) {
doc[0]; //{name: 'john', age: 10}
})
```
Change aggregation:
```
db.aggregate({$sort: 'age', $skip: 0, $limit: 12});
```
Find:
```
db.find({}, function(err, docs) {
doc[0]; //{name: 'doe', age: 8}
doc[1]; //{name: 'john', age: 10}
})
```

Sorting options can accept options as MongoDB's API allow:
http://docs.mongodb.org/manual/reference/operator/aggregation/sort/
```
db.aggregate({$sort: {age: 1, name: -1})
```

__setAtDefault Example__
Current documents:
```
{name: 'john', age: 10}
{name: 'doe', age: 8}
{name: 'eldad', age: 26}
```
Update:
```
db.aggregate({$sort:age});

db.update(
{},
{$setAsDefault: {age: 99, lastName: 'dummy'}},
{upsert: true, multi: false},
function(err, updatedNum) {
db.find({}, function(err, docs) {
docs[0]; //{name: 'doe', age: 8, lastName: 'dummy'}
docs[1]; //{name: 'john', age: 10}
docs[2]; //{name: 'eldad', age: 26}
}
}
)

```