Пример #1
0
func executeMongoGetClasses(request *messaging.ObjectRequest) (returnByte []byte) {

	session, err := mgo.Dial(request.Configuration.ServerConfiguration["MONGO"]["Url"])
	if err != nil {
		returnByte = []byte("Error getting values for all objects in mongo")
	} else {
		db := dbUse.Database{}
		db.Session = session
		db.Name = getSQLnamespace(request)
		data, err := db.CollectionNames()
		if err != nil {
			request.Log("Error getting data from Mongo")
			returnByte = []byte("Error getting data from Mongo")
		} else {

			var newData []string
			newData = make([]string, (len(data) - 1))

			index := 0
			for _, value := range data {
				if value != "system.indexes" {
					newData[index] = value
					index++
				}
			}

			byteValue, errMarshal := json.Marshal(newData)
			if errMarshal != nil {
				returnByte = []byte("Error getting values for all objects in mongo")
				request.Log("Error getting values for all objects in mongo")
			} else {
				returnByte = byteValue
				request.Log("Successfully retrieved values for all objects in mongo")
			}
		}

	}
	return
}