Skip to content

A native macOS / windows / Linux database IDE built with Swift and AppKit. Connect to PostgreSQL, MySQL, SQLite, and Redis from a single app with a fast, keyboard-driven interface.

C++

fix(mongodb): inject default db for empty-path URIs + surface MongoKittenError cases

Tobi5781ab671207
diff --git a/macos/Data/Adapters/MongoDB/MongoDBAdapter.swift b/macos/Data/Adapters/MongoDB/MongoDBAdapter.swift
index 42ea226..1e0ce8e 100644
--- a/macos/Data/Adapters/MongoDB/MongoDBAdapter.swift
+++ b/macos/Data/Adapters/MongoDB/MongoDBAdapter.swift
@@ -100,11 +100,12 @@ final class MongoDBAdapter: DatabaseAdapter, @unchecked Sendable {
return set
}()
- /// Replace the /database segment of a mongodb URI with a new database name.
- /// Preserves user:pass@host[:port] and any ?query string after the database.
+ /// Normalise the /database segment of a mongodb URI.
+ /// - If `newDB` is set, it overrides whatever's in the URI.
+ /// - Otherwise, the URI's own db is kept.
+ /// - If neither is present, `admin` is injected — `MongoDatabase.connect(to:)`
+ /// needs a concrete db name, and an empty `/?…` path would otherwise fail.
private func overrideDatabase(in uri: String, with newDB: String?) -> String {
- guard let newDB = newDB, !newDB.isEmpty else { return uri }
-
let prefix: String
let rest: String
if uri.hasPrefix("mongodb+srv://") {
@@ -133,14 +134,26 @@ final class MongoDBAdapter: DatabaseAdapter, @unchecked Sendable {
searchStart = pathPart.startIndex
}
+ let hostPart: String
+ let existingDB: String
if let slashIdx = pathPart[searchStart...].firstIndex(of: "/") {
- // Replace existing database segment
- let hostPart = String(pathPart[..<slashIdx])
- return prefix + hostPart + "/" + newDB + query
+ hostPart = String(pathPart[..<slashIdx])
+ existingDB = String(pathPart[pathPart.index(after: slashIdx)...])
} else {
- // No database in URI — append it
- return prefix + pathPart + "/" + newDB + query
+ hostPart = pathPart
+ existingDB = ""
}
+
+ let effectiveDB: String
+ if let newDB, !newDB.isEmpty {
+ effectiveDB = newDB
+ } else if !existingDB.isEmpty {
+ effectiveDB = existingDB
+ } else {
+ effectiveDB = "admin"
+ }
+
+ return prefix + hostPart + "/" + effectiveDB + query
}
/// MongoKitten error types lack NSError bridging, so the default
@@ -158,10 +171,11 @@ final class MongoDBAdapter: DatabaseAdapter, @unchecked Sendable {
let msg = reply.errorMessage ?? "MongoDB server returned an error"
let codeName = reply.codeName.map { " (\($0))" } ?? ""
message = msg + codeName
- } else if let described = error as? CustomStringConvertible {
- message = described.description
} else {
- message = error.localizedDescription
+ // MongoKittenError is a Swift enum — `localizedDescription` is useless,
+ // but `String(describing:)` prints the case name, which is the most
+ // actionable signal we can surface without version-locking to the lib.
+ message = String(describing: error)
}
return NSError(
domain: "MongoDB",
diff --git a/macos/Resources/Info.plist b/macos/Resources/Info.plist
index 9626a26..5d66407 100644
--- a/macos/Resources/Info.plist
+++ b/macos/Resources/Info.plist
@@ -32,9 +32,9 @@
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
- <string>0.0.8</string>
+ <string>0.0.9</string>
<key>CFBundleVersion</key>
- <string>8</string>
+ <string>9</string>
<key>LSMinimumSystemVersion</key>
<string>14.0</string>
<key>NSAppTransportSecurity</key>