func (c *Collection) ValidateRecordUpdate(record map[string]interface{}) *ValidationResult {
	result := &ValidationResult{Fields: make(map[string]*ValidationResult)}
	for fieldName, field := range c.Fields {
		if v, ok := record[fieldName]; ok {
			normalizedValue, normalizationResult := field.Normalize(v)
			result.Fields[fieldName] = normalizationResult
			if normalizationResult.IsValid() {
				record[fieldName] = normalizedValue
			}
		}
	}
	return result
}
TODO: underlying datasources should know how to do this-- us doing it shouldn't
be necessary
For updates we want to ensure that all fields we where given are (1) valid and (2) are ones we know about
package metadata
import (
	"encoding/json"
	"fmt"
	"strings"
	"github.com/jacksontj/dataman/datamantype"
)
func NewCollection(name string) *Collection {
	return &Collection{
		Name:    name,
		Indexes: make(map[string]*CollectionIndex),
	}
}
type Collection struct {
	ID   int64  `json:"_id,omitempty"`
	Name string `json:"name"`
	Fields map[string]*CollectionField `json:"fields"`
	Indexes map[string]*CollectionIndex `json:"indexes,omitempty"`
	PrimaryIndex *CollectionIndex `json:"-"`
	ProvisionState ProvisionState `json:"provision_state"`
}
func (c *Collection) GetName() string {
	return c.Name
}
func (c *Collection) UnmarshalJSON(data []byte) error {
	type Alias Collection
	aux := &struct {
		*Alias
	}{
		Alias: (*Alias)(c),
	}
	if err := json.Unmarshal(data, &aux); err != nil {
		return err
	}
	for _, index := range c.Indexes {
		if index.Primary {
			if c.PrimaryIndex == nil {
				c.PrimaryIndex = index
			} else {
				return fmt.Errorf("Collections can only have one primary index")
			}
		}
	}
	if c.PrimaryIndex == nil {
		return fmt.Errorf("Collection %s missing primary index", c.Name)
	}
	return nil
}
func (c *Collection) IsValidProjection(name string) bool {
	nameParts := strings.Split(name, ".")
	field := c.Fields[nameParts[0]]
	if field == nil {
		return false
	}
	for _, part := range nameParts[1:] {
		if field.SubFields == nil {
			return field.ChildrenValid()
		}
		nextField, ok := field.SubFields[part]
		if !ok {
			return field.ChildrenValid()
		}
		field = nextField
	}
	return true
}
func (c *Collection) GetFieldByName(name string) *CollectionField {
	return c.GetField(strings.Split(name, "."))
}
func (c *Collection) GetField(nameParts []string) *CollectionField {
	field := c.Fields[nameParts[0]]
	for _, part := range nameParts[1:] {
		if field == nil {
			return field
		}
		field = field.SubFields[part]
	}
	return field
}
func (c *Collection) Equal(o *Collection) bool {
	if c.Name != o.Name {
		return false
	}
	return true
}
func (c *Collection) ListIndexes() []string {
	indexes := make([]string, 0, len(c.Indexes))
	for name := range c.Indexes {
		indexes = append(indexes, name)
	}
	return indexes
}
func (c *Collection) ValidateRecordInsert(record map[string]interface{}) *ValidationResult {
	result := &ValidationResult{Fields: make(map[string]*ValidationResult)}
	for fieldName, field := range c.Fields {
		switch field.FieldType.DatamanType {
		case datamantype.Serial:
		default:
			if v, ok := record[fieldName]; ok {
				normalizedValue, normalizationResult := field.Normalize(v)
				result.Fields[fieldName] = normalizationResult
				if normalizationResult.IsValid() {
					record[fieldName] = normalizedValue
				}
			} else {
				if field.NotNull && field.Default == nil {
					result.Fields[fieldName] = &ValidationResult{
						Error: fmt.Sprintf("Missing required field %s", fieldName),
					}
				}
			}
		}
	}
	return result
}