How can i find an object that match with BinData, using Mongoose

Viewed 14

I have this schema:

const authenticatorSchema : Schema = new Schema(
    {
        _userId : {
            type : Schema.Types.ObjectId,
            ref : 'User' ,
            required : true
        },
        credentialID : {
            type : Buffer,
            required : true
        },  
        credentialPublicKey : {
            type : Buffer,
            required : true
        },
        counter : {
            type : Number,
            required : true
        },
        transports : {
            type : Array
        }
    }
)

How can i find a document by a credentialID that is type string not Buffer. I try this, but doesn't works. HELP!!!

getOneUserAuthenticator: async (_userId: string, credentialID: string): Promise<TYPE_AUTHENTICATOR | null> => {
    const credID = Buffer.from(credentialID, 'hex');
    const authenticator: TYPE_AUTHENTICATOR | null = await Authenticator.findOne({ _userId,  credentialID : credID});
    return authenticator;
  },
0 Answers
Related