Previusly only the `ObjectId` function was exposed and available
directly from the root of the `mongojs` module.
This commit exposes a couple of other BSON types in the same manner.
This is now the full list of exposed types:
- `mongojs.ObjectId`
- `mongojs.DBRef`
- `mongojs.Timestamp`
- `mongojs.MinKey`
- `mongojs.MaxKey`
- `mongojs.NumberLong` (the BSON type `Long`)
This is actually a revival commit, bringing back the spirit of the very
first Pull Request ever made to this projeect back in 2011 (later
refined in commit 06bbf02):
https://github.com/mafintosh/mongojs/pull/1
If findAndModify experiences an error, the obj argument to the callback
is undefined. Instead the lastErrorObject is attached to the err
argument, from where we extract it.
To not rely on the lastErrorObject ALWAYS being on the err object if
provided, we gracefully fall back to looking in the obj object and then
finally just return { n: 0 } if no lastErrorObject is found. This could
be a more strict algorihm, but this seems more future-proof.
- If the function was called with an array, the callback will have an array (even if the array had one element).
- If it was called with an object, the callback will have an object.
After this commit the callbacks for the write functions are as follows.
```
db.users.insert(document, callback); // => callback(err, [document])
db.users.save(document, callback); // => callback(err, document)
db.users.update({ ... }, { ... }, callback); // => callback(err, lastErrorObject)
db.users.remove({ ... }, callback); // => callback(err, {n: amountRemoved})
db.users.findAndModify({ query: { ... }, update: { ... }}, callback); // => callback(err, document, lastErrorObject)
```
The reason for these changes is that sometimes you might want to save a document and retrieve the
ObjectId it was saved with.
The problem of `save` returning '1' when the operation was an update is solved
here, and a test case was added for this as well.