MongoDB golang WriteModel Activity

I’m having some trouble getting temporal to play nice with golang mongo.WriteModels.

I have an activity it’s just a mongo.BulkWrite

// Activity
func (a *Activity) ActivityBulkDeleteManyTest(ctx context. Context, collectionName string, writeModels []mongo.WriteModel) (*mongo.BulkWriteResult, error) {
	return a.db.Collection(collectionName).BulkWrite(
		ctx,
		writeModels,
	)
}

// From WorkflowTest
val, err := env.ExecuteActivity(a.ActivityBulkDeleteManyTest, "collectionName", writeModels)
require.NoError(t, err)

The problem I’m facing is from the env.ExecuteActivity that require NoError returns the following error

unable to decode the activity function input payload with error: payload item 1: 
unable to decode: json: cannot unmarshal object into Go value of type mongo.WriteModel for function name: ActivityBulkDeleteManyTest (type: wrapError, retryable: true): 
payload item 1: unable to decode: json: cannot unmarshal object into Go value of type mongo.WriteModel (type: wrapError, retryable: true): unable to decode: json: cannot unmarshal object into Go value of type mongo.WriteModel (type: wrapError, retryable: true): unable to decode

I’ve tried implementing a custom data converter without avail one I grabbed from the pso example and tweaked to look at mongo.WriteModels

WriteModel is an interface. The only way to deserialize to an interface is to implement a custom DataConverter. I would recommend defining your own structures for activity inputs and outputs.

Yeah I have tried, I’ve also tried not using write. Model until the bulk write activity but the delete/insert all the bulk models are also interfaces and the converter strips that info out of it as well. Just trying to find some samples specific to mongo to help me out.

You can use something like GitHub - polyfloyd/gopolyjson: Go Code generator of JSON marshalers/unmarshalers for polymorphic datastructures

Or code it manually using a similar pattern to JSON polymorphism in Go. Serializing and deserializing… | by Alex Kalyvitis | Medium

MongoDataConverter would be a great open source contribution ;).

Thanks for confirming what I thought needed done, if I end up writing more than just the bulk write model I most definitely will convince my boss for us to do a contribution. I’m going to have a look at those links you gave me and see if I can get it working