mongodb custom IIdGenerator

C#
public class GuidIdGenerator : IIdGenerator
{
    public object GenerateId(object container, object document)
    {
        return Guid.NewGuid().ToString();
    }

    public bool IsEmpty(object id)
    {
    	return !(id is string guid) || string.IsNullOrEmpty(guid);
	}
}
Source

Also in C#: