Skip to content

Commit 81b48ef

Browse files
committed
c update docs + naming
1 parent ac90ef3 commit 81b48ef

File tree

2 files changed

+53
-2
lines changed

2 files changed

+53
-2
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: CI Server test
1+
name: ci-test
22

33
on:
44
push:

README.md

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# mongoose-field-encryption
22

3-
[![Build Status](https://travis-ci.org/wheresvic/mongoose-field-encryption.svg?branch=master)](https://travis-ci.org/wheresvic/mongoose-field-encryption) [![Coverage Status](https://coveralls.io/repos/github/wheresvic/mongoose-field-encryption/badge.svg?branch=master)](https://coveralls.io/github/wheresvic/mongoose-field-encryption?branch=master)
3+
![Build Status](https://github.com/wheresvic/mongoose-field-encryption/workflows/ci-test/badge.svg) [![Coverage Status](https://coveralls.io/repos/github/wheresvic/mongoose-field-encryption/badge.svg?branch=master)](https://coveralls.io/github/wheresvic/mongoose-field-encryption?branch=master)
44

55
A simple symmetric encryption plugin for individual fields. The goal of this plugin is to encrypt data but still allow searching over fields with string values. This plugin relies on the Node `crypto` module. Encryption and decryption happen transparently during save and find.
66

@@ -160,6 +160,52 @@ const encrypted = fieldEncryption.encrypt('some text', 'secret'));
160160
const decrypted = fieldEncryption.decrypt(encrypted, 'secret')); // decrypted = 'some text'
161161
```
162162

163+
### encryption of nested fields
164+
165+
Note that while this plugin is designed to encrypt only top level fields, nested fields can be easily encrypted by creating a mongoose schema for the nested objects and adding the plugin to them.
166+
167+
See comment for discussion: [https://github.com/wheresvic/mongoose-field-encryption/issues/34#issuecomment-577383776](https://github.com/wheresvic/mongoose-field-encryption/issues/34#issuecomment-577383776)
168+
169+
Example
170+
171+
```js
172+
const mongoose = require('mongoose');
173+
const mongooseFieldEncryption = require("mongoose-field-encryption").fieldEncryption;
174+
175+
const CredentialSchema = new mongoose.Schema({
176+
type: {
177+
required: true,
178+
type: String,
179+
},
180+
value: {
181+
required: true,
182+
type: String,
183+
},
184+
});
185+
186+
CredentialSchema.plugin(mongooseFieldEncryption, {
187+
fields: ["value"],
188+
secret: process.env.MONGOOSE_ENCRYPTION_KEY,
189+
});
190+
191+
const accountSchema = new mongoose.Schema({
192+
provider: {
193+
type: String,
194+
required: true,
195+
lowercase: true,
196+
trim: true,
197+
},
198+
credentials: [CredentialSchema],
199+
owner: {
200+
required: true,
201+
type: mongoose.Schema.Types.ObjectId,
202+
ref: 'User',
203+
},
204+
});
205+
206+
module.exports = mongoose.model('Account', accountSchema);
207+
```
208+
163209
## Development
164210

165211
As of version 3.0.5, one can setup a local development mongodb instance using docker:
@@ -189,6 +235,11 @@ Feel free to make changes to the default docker configuration as required.
189235

190236
## Changelog
191237

238+
### 4.0.1
239+
240+
- Update documentation to add nested field encryption example
241+
- Switch from Travis to Github actions
242+
192243
### 4.0.0
193244

194245
- _FEATURE_: Add support for an optional synchronous secret function instead of a fixed string. Note that while this change should be backwards compatible, care should be taken as an issues with the secret could lead to irrecoverable documents!

0 commit comments

Comments
 (0)