func (m *DefaultMetadataStore) GetMeta(ctx context.Context) (*metadata.Meta, error) {
	meta := metadata.NewMeta()
	fieldTypeResult := m.Store.Filter(ctx, query.QueryArgs{
		DB:            "dataman_storage",
		ShardInstance: "public",
		Collection:    "field_type",
	})
	if err := fieldTypeResult.Err(); err != nil {
		return nil, fmt.Errorf("Error in getting fieldTypeResult: %v", err)
	}
	for _, fieldTypeRecord := range fieldTypeResult.Return {
		fieldType := &metadata.FieldType{
			Name:        fieldTypeRecord["name"].(string),
			DatamanType: datamantype.DatamanType(fieldTypeRecord["dataman_type"].(string)),
		}
		fieldTypeConstraintResult := m.Store.Filter(ctx, query.QueryArgs{
			DB:            "dataman_storage",
			ShardInstance: "public",
			Collection:    "field_type_constraint",
			Filter: map[string]interface{}{
				"field_type_id": []interface{}{"=", fieldTypeRecord["_id"]},
			},
		})
		if err := fieldTypeConstraintResult.Err(); err != nil {
			return nil, fmt.Errorf("Error in getting fieldTypeResult: %v", err)
		}
		if len(fieldTypeConstraintResult.Return) > 0 {
			fieldType.Constraints = make([]*metadata.ConstraintInstance, len(fieldTypeConstraintResult.Return))
			for i, fieldTypeConstraintRecord := range fieldTypeConstraintResult.Return {
				var err error
				fieldType.Constraints[i], err = metadata.NewConstraintInstance(
					fieldType.DatamanType,
					metadata.ConstraintType(fieldTypeConstraintRecord["constraint"].(string)),
					fieldTypeConstraintRecord["args"].(map[string]interface{}),
					fieldTypeConstraintRecord["validation_error"].(string),
				)
				if err != nil {
					fmt.Println(fieldTypeRecord)
					fmt.Println(fieldTypeConstraintRecord)
					return nil, fmt.Errorf("Unable to load field_type %s: %v", fieldType.Name, err)
				}
			}
		}
		meta.FieldTypeRegistry.Add(fieldType)
	}
	databaseResult := m.Store.Filter(ctx, query.QueryArgs{
		DB:            "dataman_storage",
		ShardInstance: "public",
		Collection:    "database",
	})
	if err := databaseResult.Err(); err != nil {
		return nil, fmt.Errorf("Error getting databaseResult: %v", err)
	}
	for _, databaseRecord := range databaseResult.Return {
		database := metadata.NewDatabase(databaseRecord["name"].(string))
		database.ID = databaseRecord["_id"].(int64)
		database.ProvisionState = metadata.ProvisionState(databaseRecord["provision_state"].(int64))
		shardInstanceResult := m.Store.Filter(ctx, query.QueryArgs{
			DB:            "dataman_storage",
			ShardInstance: "public",
			Collection:    "shard_instance",
			Filter: map[string]interface{}{
				"database_id": []interface{}{"=", databaseRecord["_id"]},
			},
		})
		if err := shardInstanceResult.Err(); err != nil {
			return nil, fmt.Errorf("Error getting shardInstanceResult: %v", err)
		}
		for _, shardInstanceRecord := range shardInstanceResult.Return {
			shardInstance := metadata.NewShardInstance(shardInstanceRecord["name"].(string))
			shardInstance.ID = shardInstanceRecord["_id"].(int64)
			shardInstance.Count = shardInstanceRecord["count"].(int64)
			shardInstance.Instance = shardInstanceRecord["instance"].(int64)
			shardInstance.ProvisionState = metadata.ProvisionState(shardInstanceRecord["provision_state"].(int64))
			collectionResult := m.Store.Filter(ctx, query.QueryArgs{
				DB:            "dataman_storage",
				ShardInstance: "public",
				Collection:    "collection",
				Filter: map[string]interface{}{
					"shard_instance_id": []interface{}{"=", shardInstanceRecord["_id"]},
				},
			})
			if err := collectionResult.Err(); err != nil {
				return nil, fmt.Errorf("Error getting collectionResult: %v", err)
			}
			for _, collectionRecord := range collectionResult.Return {
				collection, err := m.getCollectionByID(ctx, meta, collectionRecord["_id"].(int64))
				if err != nil {
					return nil, fmt.Errorf("Error getCollectionByID: %v", err)
				}
				shardInstance.Collections[collection.Name] = collection
			}
			database.ShardInstances[shardInstance.Name] = shardInstance
		}
		meta.Databases[database.Name] = database
	}
	return meta, nil
}
TODO: split into get/list for each item?
TODO: have error?
package storagenode
import (
	"context"
	"fmt"
	"strings"
	"github.com/jacksontj/dataman/datamantype"
	"github.com/jacksontj/dataman/query"
	"github.com/jacksontj/dataman/storagenode/datasource"
	"github.com/jacksontj/dataman/storagenode/metadata"
)
func NewMetadataStore(config *DatasourceInstanceConfig) (*DefaultMetadataStore, error) {
	metaFunc, err := metadata.StaticMetaFunc(schemaJson)
	if err != nil {
		return nil, err
	}
	store, err := config.GetStore(metaFunc)
	if err != nil {
		return nil, err
	}
	metaStore := &DefaultMetadataStore{
		Store: store,
	}
	return metaStore, nil
}
type DefaultMetadataStore struct {
	Store datasource.DataInterface
}