mirror of
https://github.com/mainflux/mainflux.git
synced 2025-04-29 13:49:28 +08:00

* Update metadata type in things service Update things service so that metadata has map type. Update repo implementation by adding sqlx lib. Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Add sqlx lib to bootstrap service Add sqlx lib to bootstrap service and update metadata field type. Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Update metadata in redis streams consumer Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Update tests for bootstrap service Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Fix mongo reader logging and driver version Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Fix mongo reader and writer Fix mongo reader and writer by updating driver version. Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Update SDK with new metadata format Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Update LoRa adapter with new metadata format Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Update users service in order to use sqlx Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Replace anonymous struct with map Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Update docs for LoRa adapter Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Fix LoRa application metadata format Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Fix metadata format in LoRa docs Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Add metadata2 var to SDK things test Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com>
64 lines
2.4 KiB
Go
64 lines
2.4 KiB
Go
// Copyright (C) MongoDB, Inc. 2017-present.
|
|
//
|
|
// Licensed under the Apache License, Version 2.0 (the "License"); you may
|
|
// not use this file except in compliance with the License. You may obtain
|
|
// a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
// NOTE: This documentation should be kept in line with the Example* test functions.
|
|
|
|
// Package mongo provides a MongoDB Driver API for Go.
|
|
//
|
|
// Basic usage of the driver starts with creating a Client from a connection
|
|
// string. To do so, call the NewClient and Connect functions:
|
|
//
|
|
// client, err := NewClient(options.Client().ApplyURI("mongodb://foo:bar@localhost:27017"))
|
|
// if err != nil { return err }
|
|
// ctx, cancel := context.WithTimeout(context.Background(), 20*time.Second)
|
|
// defer cancel()
|
|
// err = client.Connect(ctx)
|
|
// if err != nil { return err }
|
|
//
|
|
// This will create a new client and start monitoring the MongoDB server on localhost.
|
|
// The Database and Collection types can be used to access the database:
|
|
//
|
|
// collection := client.Database("baz").Collection("qux")
|
|
//
|
|
// A Collection can be used to query the database or insert documents:
|
|
//
|
|
// res, err := collection.InsertOne(context.Background(), bson.M{"hello": "world"})
|
|
// if err != nil { return err }
|
|
// id := res.InsertedID
|
|
//
|
|
// Several methods return a cursor, which can be used like this:
|
|
//
|
|
// cur, err := collection.Find(context.Background(), bson.D{})
|
|
// if err != nil { log.Fatal(err) }
|
|
// defer cur.Close(context.Background())
|
|
// for cur.Next(context.Background()) {
|
|
// raw, err := cur.DecodeBytes()
|
|
// if err != nil { log.Fatal(err) }
|
|
// // do something with elem....
|
|
// }
|
|
// if err := cur.Err(); err != nil {
|
|
// return err
|
|
// }
|
|
//
|
|
// Methods that only return a single document will return a *SingleResult, which works
|
|
// like a *sql.Row:
|
|
//
|
|
// result := struct{
|
|
// Foo string
|
|
// Bar int32
|
|
// }{}
|
|
// filter := bson.D{{"hello", "world"}}
|
|
// err := collection.FindOne(context.Background(), filter).Decode(&result)
|
|
// if err != nil { return err }
|
|
// // do something with result...
|
|
//
|
|
// All Client, Collection, and Database methods that take parameters of type interface{}
|
|
// will return ErrNilDocument if nil is passed in for an interface{}.
|
|
//
|
|
// Additional examples can be found under the examples directory in the driver's repository and
|
|
// on the MongoDB website.
|
|
package mongo
|