The readJSONFile() function reads the data from the JSON file and returns the records in the file as a slice of Record structs.
The connect() function establishes a connection to the MongoDB database and returns a mongo.Client, context.Context, context.CancelFunc, and an error. The ping() function is used to check if the connection is successful.
The findAndValidate() function is used to find documents based on a query and validate if the total documents filtered are greater than the maximum limit. The maximum limit is set as a constant MaxMatchLimit.
The updateOne() function is used to update a single document that matches the filter with the provided update.
In the main() function, the program reads the JSON file using the readJSONFile() function and establishes a connection to the database using connect() function. It then loops through each record in the file and updates the corresponding document in the collection using the updateOne() function. The findAndValidate() function is used to validate if the document should be updated. The total matched and modified count is calculated and printed at the end.
Email: kashifkhan_9@yahoo.com