Documentation
¶
Index ¶
- Constants
- Variables
- func Aggregation(collectionName string, aggregationquery []bson.M) (result []map[string]interface{})
- func DatabaseInit()
- func DeleteFields(collectionName string, selector interface{}, updater interface{}) bool
- func Distinct(collectionName string, query interface{}, field string) (result []interface{})
- func FindAndModify(collectionName string, find interface{}, modify interface{}) (result, info interface{}, err error)
- func FindDocuments(collectionName string, query interface{}) (result []map[string]interface{})
- func FindOneDocument(collectionName string, query interface{}) (result map[string]interface{})
- func GetCount(collectionName string, selector interface{}) (int, error)
- func GetFields(collectionName string, query interface{}, selector interface{}) (result []interface{})
- func GetMappedFields(collectionName string, query interface{}, selector interface{}) (result []map[string]interface{})
- func GetMappedFieldsWithLimit(collectionName string, query interface{}, selector interface{}, limit int) (result []map[string]interface{})
- func GetResults(collectionName string, query interface{}) (result []interface{})
- func GetResultsById(collectionName string, query interface{}) (result interface{})
- func GetSortedMappedFields(collectionName string, query interface{}, selector interface{}, ...) (result []map[string]interface{})
- func GetSortedResults(collectionName string, query interface{}, sortingcriteria string) (result []interface{})
- func GetSortedResultsMap(collectionName string, query interface{}, sortingcriteria string) (result []map[string]interface{})
- func InsertDocument(collectionName string, query ...interface{}) bool
- func RemoveDocument(collectionName string, selector interface{}) (err error)
- func UpdateDocument(collectionName string, selector interface{}, update interface{}) (err error)
- func UpsertCollection(collectionName string, selector interface{}, update interface{}) (info *mgo.ChangeInfo, err error)
Constants ¶
const ( MongoDBHosts = "127.0.0.1:27017" // MongoDBHosts is your MongoDB URL. AuthDatabase = "admin" // The database that contains the authorization credentials for your MongoDB database. Leave this and all further fields blank if you're running MongoDB without authentication. AuthUserName = "user" // The user through which you would like to access your MongoDB database. This user could have read or write access or both. In case it has only read access, some of GoMongo's functions may result in failure. AuthPassword = "password" // The password for the user which has authenticated access to your MongoDB database. TestDatabase = "testdb" // This constant holds the name of a test database, so that you can quickly change from the main DB to a test DB using the Dbname variable below.Aggregation )
Variables ¶
var ( MgoSession *mgo.Session Dbname = "targetdb" // Database that contains the actual information that is required to be queried. )
Functions ¶
func Aggregation ¶
func Aggregation(collectionName string, aggregationquery []bson.M) (result []map[string]interface{})
Aggregation function provides a medium to use the MongoDB Aggregation Framework.
func DeleteFields ¶
DeleteFields is actually an Update operation but can delete whole documents as well.
func FindAndModify ¶
func FindAndModify(collectionName string, find interface{}, modify interface{}) (result, info interface{}, err error)
FindAndModify function to find and modify in a single step
func FindDocuments ¶
FindDocuments is an 'All' variant of FindOneDocument. Returns all matching results as an array of maps.
func FindOneDocument ¶
FindOneDocument is a lot like GetResultsById but the return type here is map[string]interface{} instead of just an interface{}.
func GetFields ¶
func GetFields(collectionName string, query interface{}, selector interface{}) (result []interface{})
GetFields function uses a projection to show only those fields that are required. Returns all matching fields.
func GetMappedFields ¶
func GetMappedFields(collectionName string, query interface{}, selector interface{}) (result []map[string]interface{})
GetMappedFields is similar to GetResults but returns an array of maps instead of an array of interfaces.
func GetMappedFieldsWithLimit ¶
func GetMappedFieldsWithLimit(collectionName string, query interface{}, selector interface{}, limit int) (result []map[string]interface{})
GetMappedFieldsWithLimit is similar to GetMappedFields but uses Limit and Iter to return only the number of results that are required.
func GetResults ¶
func GetResults(collectionName string, query interface{}) (result []interface{})
GetResults function will return all results for a given query.
func GetResultsById ¶
func GetResultsById(collectionName string, query interface{}) (result interface{})
GetResultsById is a variant of GetResults which returns one result - matching a given set of criteria, which is supposed to be an ID. This function could be modified in later versions to match only ID as that's a frequent requirement in MongoDB-backed data.
func GetSortedMappedFields ¶
func GetSortedMappedFields(collectionName string, query interface{}, selector interface{}, sortingcriteria string) (result []map[string]interface{})
GetSortedMappedFields function will return only the requested fields sorted as per sorting criteria in the form of an array of maps.
func GetSortedResults ¶
func GetSortedResults(collectionName string, query interface{}, sortingcriteria string) (result []interface{})
GetSortedResults function will return results sorted as per sorting criteria.
func GetSortedResultsMap ¶
func GetSortedResultsMap(collectionName string, query interface{}, sortingcriteria string) (result []map[string]interface{})
GetSortedResultsMap function will return results sorted as per sorting criteria in the form of an array of maps.
func InsertDocument ¶
InsertDocument function accepts any number of queries to insert to a document. Returns success or failure as boolean.
func RemoveDocument ¶
RemoveDocument to remove all documents matching given conditions. Avoid using DeleteFields for this purpose.
func UpdateDocument ¶
UpdateDocument will update fields matching the given query. Use $set with this to retain other fields.
func UpsertCollection ¶
func UpsertCollection(collectionName string, selector interface{}, update interface{}) (info *mgo.ChangeInfo, err error)
UpsertCollection is a standard Upsert operation. Returns changeInfo and error.
Types ¶
This section is empty.