gomongofixtures

package module
v0.0.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 10, 2020 License: MIT Imports: 9 Imported by: 0

README

GOMONGOFIXTURE

It is a simple library to load MongoDB data from files generated by mongoexport utility into your database for testing reasons or whatever reason you'd like.

Documentation

Overview

Package gomongofixtures contains methods for loading MongoDB data from files generated by mongoexport utility into your database for testing reasons or whatever reason you'd like.

Usage:

if err := Load(context.Background(), "localhost:27017", Fixture{
	DB:   "db",
	Path: "data.json",
}); err != nil {
	panic(err)
}

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Load

func Load(ctx context.Context, uri string, f Fixture) error

Load loads the given fixture into a database with the given URI using Loader. Each time it creates new Loader and new connection to the database. It uses file name in the path of the fixture as a collection name.

Types

type Fixture

type Fixture struct {
	Path string
	DB   string
}

Fixture describes a fixture: path to a file, database and collection the fixture should be loaded in.

type Loader

type Loader struct {
	URI  string // URI of MongoDB.
	Path string // Path to fixture file.
	DB   string // Database name to load fixture.
	Col  string // Collection to load fixture.
}

Loader loads fixtures into a database.

func (*Loader) Load

func (l *Loader) Load(ctx context.Context) error

Load connects to the database and loads the fixture.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL