在 Swift 中查询我的缝合远程集合时出现以下错误:no response from server: unknown: transportError
这是我的测试查询:
//var aircraftCollection: RemoteMongoCollection<Aircraft>!
var aircraftCollection: RemoteMongoCollection<Document>!
var mongoDb = MongoDB()
class MongoDB: ErrorListener {
init() {
do {
let client = try Stitch
.initializeDefaultAppClient(withClientAppID: "....")
let mongoClient = try client.serviceClient(
fromFactory: remoteMongoClientFactory, withName: "...."
)
client.auth.login(withCredential: UserPasswordCredential(withUsername: "....", withPassword: "....")) { result in
switch result {
case .success(let user):
// Get collections from database
aircraftCollection = mongoClient.db("database").collection("aircraft")
let aircraft = Document(dictionaryLiteral: ("_id", ObjectId()))
aircraftCollection.sync.insertOne(document: aircraft, { (result) in
switch result {
case .success(_):
print("inserted successfully")
case .failure(let e):
fatalError(e.localizedDescription)
}
})
aircraftCollection.find().first { result in
switch result {
case .success(let aircraft):
let aircraftList = aircraft.map { $0 }
print(aircraftList)
case .failure(let error):
// this is where error occurs
print(error.localizedDescription)
}
}
case .failure(let error):
print("Error in login: \(error)")
}
}
} catch let error {
print("do catch error")
print(error)
}
}
我的连接似乎很好,我在 localhost 上有另一个用 JavaScript 构建的缝合应用程序,它可以毫无问题地执行相同的查询。我在用pod 'StitchSDK', '~> 5.0.0'