Uploaded image for project: 'MongoDB Database Tools'
  1. MongoDB Database Tools
  2. TOOLS-1972

Hint the _id index instead of using $snapshot query option

    • Type: Icon: Task Task
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 3.7.4
    • Affects Version/s: None
    • Component/s: None
    • None
    • Query 2018-03-26

      $snapshot is being removed in MongoDB 4.0, SERVER-32174. As a workaround, hint the _id index:

      diff --git a/src/mongo/gotools/common/db/command.go b/src/mongo/gotools/common/db/command.go
      index f777d94..159bdfb 100644
      --- a/src/mongo/gotools/common/db/command.go
      +++ b/src/mongo/gotools/common/db/command.go
      @@ -204,7 +204,9 @@ func (sp *SessionProvider) FindOne(db, collection string, skip int, query interf
       // ApplyFlags applies flags to the given query session.
       func ApplyFlags(q *mgo.Query, session *mgo.Session, flags int) *mgo.Query {
       	if flags&Snapshot > 0 {
      -		q = q.Snapshot()
      +		// The snapshot option for find has been removed in the server, workaround by hinting the 
      +		// _id index instead.
      +		q = q.Hint("_id")
       	}
       	if flags&LogReplay > 0 {
       		q = q.LogReplay()
      diff --git a/src/mongo/gotools/mongodump/mongodump.go b/src/mongo/gotools/mongodump/mongodump.go
      index 41b37e3..e05b83e 100644
      --- a/src/mongo/gotools/mongodump/mongodump.go
      +++ b/src/mongo/gotools/mongodump/mongodump.go
      @@ -544,7 +544,7 @@ func (dump *MongoDump) DumpIntent(intent *intents.Intent, buffer resettableOutpu
       		// ---forceTablesScan runs the query without snapshot enabled
       		findQuery = session.DB(intent.DB).C(intent.C).Find(nil)
       	default:
      -		findQuery = session.DB(intent.DB).C(intent.C).Find(nil).Snapshot()
      +		findQuery = session.DB(intent.DB).C(intent.C).Find(nil).Hint("_id")
       	}
       
       	var dumpCount int64
      -- 
      2.7.4
      

            Assignee:
            nicholas.zolnierz@mongodb.com Nicholas Zolnierz
            Reporter:
            kelsey.schubert@mongodb.com Kelsey Schubert
            Votes:
            0 Vote for this issue
            Watchers:
            8 Start watching this issue

              Created:
              Updated:
              Resolved: