2017-10-11 79 views

回答

0

就在幾個月前,我對自己提出了同樣的問題。這是我迄今發現的選項列表:

0

Alex Blex suggested一樣,您可以使用Community Edition以外的其他選項。

但是,如果你還是想要去與社區版,

可以使用mongoose.js與MongoDB的交互。它有getter和setter能滿足您的要求:
http://mongoosejs.com/docs/2.7.x/docs/getters-setters.html

在你的貓鼬的模式,可以爲字段指定getset功能。

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}); 

set將在您將任何值分配給該字段時執行。它會將該值作爲參數,然後您可以編寫自己的加密邏輯。

只要您訪問字段的值,就會執行get。它將獲得加密值作爲參數,您可以在此處編寫解密邏輯。您需要編寫decryptFunctionencryptFunction

但是,你將無法查詢與原始值的這些字段。由於mongodb不知道文本是否被加密。

相關問題