Uploaded image for project: 'Swift Driver'
  1. Swift Driver
  2. SWIFT-404

expireAfter index option is not correctly encoded

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major - P3
    • Resolution: Fixed
    • Affects Version/s: 0.1.0
    • Fix Version/s: 0.1.1
    • Component/s: None
    • Labels:
      None
    • Environment:
      macOS, Vapor

      Description

      Creating new indexes with expireAfter throws an error:

      Example code:

       

      
      

      *// Configure Mongo
      let client = try MongoClient(Constants.mongo.url)
      services.register(client)

      let model = IndexModel(keys: ["createdAt": 1], options: IndexOptions(expireAfter: 10))
      try client.db("auth").collection("keys").createIndex(model)*

       

       

      Error:

       

      
      

      *Fatal error: Error raised at top level: MongoSwift.ServerError.commandError(code: 197, message: "The field \'expireAfter\' is not valid for an index specification. Specification: { key:

      { createdAt: 1 }

      , name: \"createdAt_1\", expireAfter: 10 }", errorLabels: nil): file /BuildRoot/Library/Caches/com.apple.xbs/Sources/swiftlang/swiftlang-1001.8.63.13/swift/stdlib/public/core/ErrorType.swift, line 200***

       

      The problem is that Mongo expects a parameter name expireAfterSeconds and MongoSwift uses expireAfter.

      There are a simple solutions applying to IndexModel struct

      1. Change expireAfter key to expireAfterSeconds
      2. Add coding key string like expireAfter = "expireAfterSeconds"

        Attachments

          Activity

            People

            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: