-
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
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
- Change expireAfter key to expireAfterSeconds
- Add coding key string like expireAfter = "expireAfterSeconds"