From 6a655af878199c49512621a7f24955417e8ddcaa Mon Sep 17 00:00:00 2001 From: lyric Date: Sun, 29 May 2016 23:07:45 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E4=BB=A4=E7=89=8C=E5=AD=98?= =?UTF-8?q?=E5=82=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tokenMongoStore.go | 6 +++--- tokenStore.go | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/tokenMongoStore.go b/tokenMongoStore.go index 0edaa73..eeeefe7 100644 --- a/tokenMongoStore.go +++ b/tokenMongoStore.go @@ -22,7 +22,7 @@ func NewTokenMongoStore(mongoConfig *MongoConfig, cName string) (TokenStore, err if cName == "" { cName = DefaultTokenCollectionName } - err = mHandler.C(cName).EnsureIndexKey("ID", "AccessToken", "RefreshToken") + err = mHandler.C(cName).EnsureIndexKey("AccessToken", "RefreshToken") if err != nil { return nil, err } @@ -58,7 +58,7 @@ func (tm *TokenMongoStore) Create(item *Token) (id int64, err error) { // Update Modify item func (tm *TokenMongoStore) Update(id int64, info map[string]interface{}) (err error) { tm.mHandler.CHandle(tm.cName, func(c *mgo.Collection) { - err = c.Update(bson.M{"ID": id}, bson.M{"$set": info}) + err = c.UpdateId(id, bson.M{"$set": info}) if err != nil { return } @@ -69,7 +69,7 @@ func (tm *TokenMongoStore) Update(id int64, info map[string]interface{}) (err er func (tm *TokenMongoStore) findOne(query interface{}) (token *Token, err error) { tm.mHandler.CHandle(tm.cName, func(c *mgo.Collection) { var result []Token - err = c.Find(query).Sort("-ID").Limit(1).All(&result) + err = c.Find(query).Sort("-_id").Limit(1).All(&result) if err != nil { return } diff --git a/tokenStore.go b/tokenStore.go index cee1458..dbbf3f7 100644 --- a/tokenStore.go +++ b/tokenStore.go @@ -6,7 +6,7 @@ import ( // Token 令牌信息 type Token struct { - ID int64 `bson:"ID"` // 唯一标识(自增ID) + ID int64 `bson:"_id"` // 唯一标识(自增ID) ClientID string `bson:"ClientID"` // 客户端标识 UserID string `bson:"UserID"` // 用户标识 AccessToken string `bson:"AccessToken"` // 访问令牌