You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: consumer.go
    path of file: ./repos/magistrala/consumers/writers/mongodb
    
    the code of the file until where you have to start completion: // Copyright (c) Abstract Machines
// SPDX-License-Identifier: Apache-2.0

package mongodb

import (
	"context"

	"github.com/absmach/magistrala/consumers"
	"github.com/absmach/magistrala/pkg/errors"
	"github.com/absmach/magistrala/pkg/transformers/json"
	"github.com/absmach/magistrala/pkg/transformers/senml"
	"go.mongodb.org/mongo-driver/bson"
	"go.mongodb.org/mongo-driver/mongo"
)

const senmlCollection string = "messages"

var errSaveMessage = errors.New("failed to save message to mongodb database")

var _ consumers.BlockingConsumer = (*mongoRepo)(nil)

type mongoRepo struct {
	d
    
func (repo *mongoRepo) saveSenml(ctx context.Context, messages interface{}) error {
	msgs, ok := messages.([]senml.Message)
	if !ok {
		return errSaveMessage
	}
	coll := repo.db.Collection(senmlCollection)
	var dbMsgs []interface{}
	for _, msg := range msgs {
		// Check if message is already in database.
		filter := bson.M{"time": msg.Time, "publisher": msg.Publisher, "subtopic": msg.Subtopic, "name": msg.Name}

		count, err := coll.CountDocuments(ctx, filter)
		if err != nil {
			return errors.Wrap(errSaveMessage, err)
		}

		if count == 0 {
			dbMsgs = append(dbMsgs, msg)
		}
	}

	_, err := coll.InsertMany(ctx, dbMsgs)
	if err != nil {
		return errors.Wrap(errSaveMessage, err)
	}

	return nil
}