Mongocrypt error 1: invalid msg, must contain 'v'"

Hello,

I am trying to find the solution to a problem I am having attempting to use some of the encryption related methods. Originally I was following the entire CSFLE / AWS tutorial, but eventually found this method for the ClientEncryption sub-type

Encrypt(ctx context.Context, val bson.RawValue, opts 
      ...*options.EncryptOptions) (primitive.Binary, error)`

When attempting to use it, I get the error in the title of this topic:
mongocrypt error 1: invalid msg, must contain 'v'"

What does this error mean, and how can I assess it? I’ve followed most of the CSFLE/AWS tutorial for GoLang meaning I’ve set up a KeyVault, a DEK, and created an encryption client.

This error indicates that the argument passed to the val parameter of the Encrypt method uses an invalid bson encoding, or no encoding at all: bson.RawValue{}. For instance, the following would cause this error since it uses a json encoding for the string type:

jbytes, _ := json.Marshal("someString")
encryptedField, err := clientEncryption.Encrypt(
	context.TODO(),
	bson.RawValue{Type: bson.TypeString, Value: jbytes},
	nil)

This can be resolved by using bson.MarshalValue to construct bson.RawValue:

rawValueType, rawValueData, _ := bson.MarshalValue("someString")
encryptedField, err := clientEncryption.Encrypt(
	context.TODO(),
	bson.RawValue{Type: rawValueType, Value: rawValueData},
	nil)
1 Like

Thanks for getting back to me so quickly! This worked perfectly. Thanks for this

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.