本文整理汇总了Golang中gopkg/in/mgo/v2/bson.M函数的典型用法代码示例。如果您正苦于以下问题:Golang M函数的具体用法?Golang M怎么用?Golang M使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了M函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: SetUserDetailInfo
func SetUserDetailInfo(sel, set map[string]interface{}) error {
c := common.MongoCollection("dudb", "user_detail_info")
if err := c.Update(bson.M(sel), bson.M{"$set": bson.M(set)}); err != nil {
return errors.As(err, sel, set)
}
return nil
}
示例2: SetUserInfo
func SetUserInfo(sel, set map[string]interface{}) error {
c := common.MongoCollection(USER_DB, USER_INFO_TABLE)
if err := c.Update(bson.M(sel), bson.M{"$set": bson.M(set)}); err != nil {
return errors.As(err, sel, set)
}
return nil
}
示例3: SetTeamMember
func SetTeamMember(sel, set map[string]interface{}) error {
c := common.MongoCollection(TEAM_DB, TEAM_MEMBER_TABLE)
if err := c.Update(bson.M(sel), bson.M{"$set": bson.M(set)}); err != nil {
return errors.As(err, sel, set)
}
return nil
}
示例4: setUnsetUpdateAnnotations
// setUnsetUpdateAnnotations returns a bson.D for use
// in an annotationsC txn.Op's Update field, containing $set and
// $unset operators if the corresponding operands
// are non-empty.
func setUnsetUpdateAnnotations(set, unset bson.M) bson.D {
var update bson.D
replace := inSubdocReplacer("annotations")
if len(set) > 0 {
set = bson.M(copyMap(map[string]interface{}(set), replace))
update = append(update, bson.DocElem{"$set", set})
}
if len(unset) > 0 {
unset = bson.M(copyMap(map[string]interface{}(unset), replace))
update = append(update, bson.DocElem{"$unset", unset})
}
return update
}
示例5: InsertSingle
func (repository MongoRepository) InsertSingle(request *messaging.ObjectRequest) RepositoryResponse {
request.Log("Starting INSERT-SINGLE")
response := RepositoryResponse{}
collection, isError, errorMessage := getMongoConnection(request)
key := getMongoDBRecordID(request, nil)
if isError == true {
response.GetErrorResponse(errorMessage)
} else if key != "" {
request.Body.Object[request.Body.Parameters.KeyProperty] = key
request.Body.Object["_id"] = request.Controls.Namespace + "." + request.Controls.Class + "." + key
err := collection.Insert(bson.M(request.Body.Object))
if err != nil {
response.IsSuccess = false
response.GetErrorResponse("Error inserting one object in mongo" + err.Error())
} else {
response.IsSuccess = true
response.Message = "Successfully inserted one object in Mongo"
request.Log(response.Message)
}
}
var Data []map[string]interface{}
Data = make([]map[string]interface{}, 1)
var actualData map[string]interface{}
actualData = make(map[string]interface{})
actualData["ID"] = key
Data[0] = actualData
response.Data = Data
return response
}
示例6: GetOneModel
func (db *MongoDatabaseSession) GetOneModel(mongoQuery M, result interface{}) error {
collectionName := tools.GetInnerTypeName(result)
log.Println(collectionName)
collection := db.Database.C(collectionName)
err := collection.Find(bson.M(mongoQuery)).One(result)
return err
}
示例7: setUnsetUpdateSettings
// setUnsetUpdateSettings returns a bson.D for use
// in a settingsC txn.Op's Update field, containing
// $set and $unset operators if the corresponding
// operands are non-empty.
func setUnsetUpdateSettings(set, unset bson.M) bson.D {
var update bson.D
replace := inSubdocReplacer("settings")
if len(set) > 0 {
set = bson.M(copyMap(map[string]interface{}(set), replace))
update = append(update, bson.DocElem{"$set", set})
}
if len(unset) > 0 {
unset = bson.M(copyMap(map[string]interface{}(unset), replace))
update = append(update, bson.DocElem{"$unset", unset})
}
if len(update) > 0 {
update = append(update, bson.DocElem{"$inc", bson.D{{"version", 1}}})
}
return update
}
示例8: confirm
// confirm adds to filter confirm clause
func confirm(filter model.Fields) bson.M {
if filter == nil {
filter = model.Fields{}
}
filter["confirm"] = true
return bson.M(filter)
}
示例9: ReadAppBuildTaskList
func ReadAppBuildTaskList(m map[string]interface{}) ([]AppBuildTask, error) {
fmt.Println(m)
fmt.Println(bson.M(m))
var list []AppBuildTask
err := taskCollection.Find(m).All(&list)
return list, err
}
示例10: buildUpdateObj
func (bs *BaseStack) buildUpdateObj(m *stack.Machine, s *DialState, now time.Time) bson.M {
obj := object.MetaBuilder.Build(bs.Provider.newMetadata(m))
obj["credential"] = m.Credential.Identifier
obj["provider"] = bs.Provider.Name
obj["queryString"] = m.QueryString
obj["status.modifiedAt"] = now
obj["status.state"] = m.State.String()
obj["status.reason"] = m.StateReason
if s.KiteURL != "" {
obj["registerUrl"] = s.KiteURL
if u, err := url.Parse(s.KiteURL); err == nil && u.Host != "" {
if host, _, err := net.SplitHostPort(u.Host); err == nil {
u.Host = host
}
obj["ipAddress"] = u.Host
}
}
bs.Log.Debug("update object for %q: %+v (%# v)", m.Label, obj, s)
return bson.M(obj)
}
示例11: GetUser
//mongodb_user
func (d *MongoDb) GetUser(user_prop map[string]interface{}) (user utah.User, err error) {
c := d.Session.DB(d.dbname).C(d.users_c_name)
err = c.Find(bson.M(user_prop)).One(&user)
if err != nil {
return user, err
}
return user, nil
}
示例12: GetTeamList
func GetTeamList(sel map[string]interface{}, start, count int) ([]TeamInfo, error) {
c := common.MongoCollection(TEAM_DB, TEAM_INFO_TABLE)
team_list := []TeamInfo{}
err := c.Find(bson.M(sel)).Skip(start).Limit(count).All(&team_list)
return team_list, errors.As(err, sel)
}
示例13: GetUserInfo
func GetUserInfo(sel map[string]interface{}) (*UserInfo, error) {
c := common.MongoCollection(USER_DB, USER_INFO_TABLE)
user := &UserInfo{}
if err := c.Find(bson.M(sel)).One(user); err != nil {
return nil, errors.As(err, sel)
}
return user, nil
}
示例14: GetModels
//GetModels retrieves all the data from mongoDB
//mongoQuery is the query from MongoDB query
//resultInterface is a slice representing the model required, it will be fill with the result of the query
//limit of result if limit < 0 no limit used
//skip corresponding the number elements to skip
//return an err if soimething bad appened
func (db *MongoDatabaseSession) GetModels(mongoQuery M, resultInterface interface{}, limit int, skip int) (interface{}, error) {
collectionName := tools.GetInnerTypeName(resultInterface)
collection := db.Database.C(collectionName)
result := tools.CreatePtrToSliceFromInterface(resultInterface)
var err error = nil
switch {
case limit <= 0 && skip <= 0:
err = collection.Find(bson.M(mongoQuery)).All(result)
case limit > 0 && skip <= 0:
err = collection.Find(bson.M(mongoQuery)).Limit(limit).All(result)
case limit <= 0 && skip > 0:
err = collection.Find(bson.M(mongoQuery)).Skip(skip).All(result)
case limit > 0 && skip > 0:
err = collection.Find(bson.M(mongoQuery)).Skip(skip).Limit(limit).All(result)
}
resultInterface = tools.Dereference(result)
return resultInterface, err
}
示例15: Fire
// Fire - the log event
func (h *mongoDB) Fire(entry *logrus.Entry) error {
entry.Data["Level"] = entry.Level.String()
entry.Data["Time"] = entry.Time
entry.Data["Message"] = entry.Message
mgoErr := h.c.Insert(bson.M(entry.Data))
if mgoErr != nil {
return fmt.Errorf("Failed to send log entry to mongodb: %s", mgoErr)
}
return nil
}