<commit_before># What
Is a mongoose plugin that automatically keeps track of when the document has been created, updated and optionally when some fields have been modified

[![Build Status](https://travis-ci.org/gabrielelana/mongoose-trackable.png?branch=master)](https://travis-ci.org/gabrielelana/mongoose-trackable)

# Install
`npm install mongoose-trackable`

# Usage
```javascript
// see examples/track_model.js

var OrderSchema = new mongoose.Schema({products: Array}).plugin(trackable)

var Order = mongoose.model('Order', OrderSchema)

Order.create({products: ['apple']}, function(err, order) {
  // order now has createdAt and updatedAt fields

  order.products.push('cucumber')
  order.save(function(err, order) {
    // updatedAt has been updated with the last save
  })
})
```
Order is a trackable model, by default a trackable model will tracke the creation time in the `createdAt` field and last update time in the `updatedAt` field

Moreover you can keep track of all the changes of a certain field using the option `fieldsToTrack`
```javascript
// see examples/track_field.js

var OrderSchema = new mongoose.Schema({products: Array, status: String})
  .plugin(trackable, {fieldsToTrack: ['status']})

var Order = mongoose.model('Order', OrderSchema)

Order.create({status: 'placed', products: ['apple', 'cucumber']}, function(err, order) {
  // order now has __updates field that contains something like
  // [
  //    {"field":"status","changedTo":"placed","at":"2014-01-18T13:51:04.780Z"}
  // ]

  order.status = 'shipped'
  order.save(function(err, order) {
    // now __updates contains also the last status update
    // [
    //    {"field":"status","changedTo":"placed","at":"2014-01-18T13:51:04.780Z"},
    //    {"field":"status","changedTo":"shipped","at":"2014-01-18T13:51:04.808Z"}
    // ]
  })
})
```

For more options and more use cases see `spec/acceptance.js`

# TODO
* more and better documentation
* skiptToTrackDocumentUpdates vs skipToTrackFieldsUpdates<commit_msg>Fixed typo in README<commit_after># What
Is a mongoose plugin that automatically keeps track of when the document has been created, updated and optionally when some fields have been modified

[![Build Status](https://travis-ci.org/gabrielelana/mongoose-trackable.png?branch=master)](https://travis-ci.org/gabrielelana/mongoose-trackable)

# Install
`npm install mongoose-trackable`

# Usage
```javascript
// see examples/track_model.js

var OrderSchema = new mongoose.Schema({products: Array}).plugin(trackable)

var Order = mongoose.model('Order', OrderSchema)

Order.create({products: ['apple']}, function(err, order) {
  // order now has createdAt and updatedAt fields

  order.products.push('cucumber')
  order.save(function(err, order) {
    // updatedAt has been updated with the last save
  })
})
```
Order is a trackable model, by default a trackable model will track the creation time in the `createdAt` field and last update time in the `updatedAt` field

Moreover you can keep track of all the changes of a certain field using the option `fieldsToTrack`
```javascript
// see examples/track_field.js

var OrderSchema = new mongoose.Schema({products: Array, status: String})
  .plugin(trackable, {fieldsToTrack: ['status']})

var Order = mongoose.model('Order', OrderSchema)

Order.create({status: 'placed', products: ['apple', 'cucumber']}, function(err, order) {
  // order now has __updates field that contains something like
  // [
  //    {"field":"status","changedTo":"placed","at":"2014-01-18T13:51:04.780Z"}
  // ]

  order.status = 'shipped'
  order.save(function(err, order) {
    // now __updates contains also the last status update
    // [
    //    {"field":"status","changedTo":"placed","at":"2014-01-18T13:51:04.780Z"},
    //    {"field":"status","changedTo":"shipped","at":"2014-01-18T13:51:04.808Z"}
    // ]
  })
})
```

For more options and more use cases see `spec/acceptance.js`

# TODO
* more and better documentation
* `skiptToTrackDocumentUpdates` vs `skipToTrackFieldsUpdates`
{'fraction_non_alphanumeric': 0.14043824701195218, 'fraction_numerical': 0.025398406374501994, 'mean_word_length': 4.657746478873239, 'pattern_counts': {'":': 18, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5718776', 'n_tokens_mistral': 1302, 'n_tokens_neox': 1232, 'n_words': 354}