I've gone through MongoDB docs that explain how to configure encryption which is available in MongoDB Enterprise only.
How to implement data at rest in MongoDB Community Edition v3.4?
I've gone through MongoDB docs that explain how to configure encryption which is available in MongoDB Enterprise only.
How to implement data at rest in MongoDB Community Edition v3.4?
I was asking the same question to myself just few month ago. This is a list of options I have found so far:
Like Alex Blex suggested, you have other options than Community Edition.
However, if you still want to go with Community Edition,
You can use mongoose.js for interacting with mongoDB. It has getters and setters that can fulfill your requirement:
http://mongoosejs.com/docs/2.7.x/docs/getters-setters.html
In your mongoose schema, you can specify get
and set
functions for fields.
var mySchema = new Schema({
name: {
type: String,
default: '',
trim: true,
required: 'Please enter group name',
unique: true,
get: decryptFunction,
set: encryptFunction
}
});
mySchema.set('toObject', {getters: true});
mySchema.set('toJSON', {getters: true});
The set
will be executed whenever you are assigning any value to the field. It will take the value as a parameter, and then you can write your own encryption logic.
The get
will be executed whenever you access the field's value. It will get the encrypted value as a parameter and you can write your decryption logic there.
You will have to write the decryptFunction
and encryptFunction
.
However, you wont be able to query those fields with original values. As the mongodb does not know the text is encrypted.