watson / mongodown

A drop-in replacement for LevelDOWN that runs on MongoDB
MIT License
28 stars 16 forks source link

feat: add "extraFields" option #21

Closed dmitryverkhovtsev closed 1 year ago

dmitryverkhovtsev commented 2 years ago

By default mongodown will store the level value in the "value" property. If you need to save additional data with mongo document then you can do that with "extraFields" option. Extra field value can be derived from key and value of "put" operations.

This will add timestamp key to mongo document on put:

var db = levelup(mongodown('localhost/my-database'), {
  extraFields: {
    timestamp: function (k,v) { return Date.now() }
  }
})