Documentation ¶
Index ¶
- type MongoConfig
- func (mc *MongoConfig) Connect() (*mongo.Collection, error)
- func (mc *MongoConfig) CreateDocuments(docs []interface{}) error
- func (mc *MongoConfig) Disconnect()
- func (mc *MongoConfig) GetAllDocuments(filter interface{}, opts *options.FindOptions, fn func(doc bson.M) error) error
- func (mc *MongoConfig) GetDocument(verbose bool, ps *util.PartialSchema, id string) (map[string]interface{}, error)
- type SolrConfig
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type MongoConfig ¶
type MongoConfig struct { MongoAddress string `help:"Address of the MongoDB server."` MongoDatabase string `help:"Database to access on the MongoDB server."` MongoCollection string `help:"Collection to access on the MongoDB server."` MongoTimeout int `help:"Timeout (in seconds) for Mongo connections." default:"30"` // The context used to connect to this instance of MongoDB. You can use this // to make further MongoDB calls. Context context.Context // contains filtered or unexported fields }
MongoConfig encapsulates the list of command-line parameters needed to connect to MongoDB, along with some utility code.
func (*MongoConfig) Connect ¶
func (mc *MongoConfig) Connect() (*mongo.Collection, error)
Connect connects to MongoDB, given the connection parameters in this configuration.
func (*MongoConfig) CreateDocuments ¶
func (mc *MongoConfig) CreateDocuments(docs []interface{}) error
CreateDocuments creates documents, from a slice of Go primitives. The types in the primitives will be serialized according to the way in which Go types are automatically converted by Mongo's BSON library:
https://pkg.go.dev/go.mongodb.org/mongo-driver/bson#hdr-Native_Go_Types
func (*MongoConfig) Disconnect ¶
func (mc *MongoConfig) Disconnect()
Disconnect disconnects from MongoDB. Whenever you call `mc.Connect()`, you should immediately call `defer mc.Disconnect()`.
func (*MongoConfig) GetAllDocuments ¶
func (mc *MongoConfig) GetAllDocuments(filter interface{}, opts *options.FindOptions, fn func(doc bson.M) error) error
GetAllDocuments calls the given callback for every document in the database, possibly filtered by the given filter (usually a bson.D{}) and options.
If the callback returns a non-nil error, further iteration will be aborted. There will be no filtering or transforms at all performed on the returned BSON document objects.
func (*MongoConfig) GetDocument ¶
func (mc *MongoConfig) GetDocument(verbose bool, ps *util.PartialSchema, id string) (map[string]interface{}, error)
GetDocument returns a single document, as a Go primitive. Note that the id value here is not the Mongo document ID, but the ID value of the document itself (i.e., the Sciveyor ID).
This document will be cleaned before it is returned to the user; it will contain only those fields present in the canonical JSON schema, and hence only those fields that are acceptable to be immediately sent to Solr.
type SolrConfig ¶
type SolrConfig struct { SolrAddress string `help:"URL of the root of the Solr server."` SolrCollection string `help:"Collection to load on the Solr server."` }
SolrConfig encapsulates the list of command-line parameters needed to connect to Solr.
func (*SolrConfig) Commit ¶
func (sc *SolrConfig) Commit() error
Commit commits all current changes to Solr.
func (*SolrConfig) Connect ¶
func (sc *SolrConfig) Connect() (*solr.SolrInterface, error)
Connect connects to a Solr server using the given configuration parameters.
func (*SolrConfig) CreateDocument ¶
func (sc *SolrConfig) CreateDocument(document map[string]interface{}) error
CreateDocument adds the given document to the Solr database.
We simply assume that the given document object has all and only the correct properties set that you want to send to Solr; no checking of this object is done before it is serialized and sent.
Also note that this function will delete and re-add the given document. It's not worth our time to see which fields of the document may have changed and compose a proper Solr delta-update message.
func (*SolrConfig) DeleteDocument ¶
func (sc *SolrConfig) DeleteDocument(id string) error
DeleteSolrDocument removes the given document from the Solr database.
FIXME: Does this error if the doc doesn't exist?