Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Connection issue #8

Open
iMac0de opened this issue Oct 30, 2017 · 1 comment
Open

Connection issue #8

iMac0de opened this issue Oct 30, 2017 · 1 comment

Comments

@iMac0de
Copy link

iMac0de commented Oct 30, 2017

Hi guys,

I was trying to use MongoDB-StORM but I am facing an issue during with the connection.

I have set my default settings in the main.swift file:
MongoDBConnection.host = "localhost"
MongoDBConnection.port = 27017
MongoDBConnection.ssl = false
MongoDBConnection.database = "mydb"

But when I am trying to save an object, I got this error:

The operation couldn’t be completed. (StORM.StORMError error 0.)

I have tried with PerfectMongoDB directly by creating a client, then the database and then get a collection and I have no error with the same parameters.

Also, I check your code in the MongoDBStORM.swift file and I saw that when you are trying to create a MongoClient you use the MongoDBConnection.host parameter but not the MongoDBConnection.port parameter, so maybe the problem is from there.

Thanks.

@iMac0de
Copy link
Author

iMac0de commented Nov 2, 2017

Hi guys,

Some news about this issue, I found out that the problem came from an Enum in my User object.

I need to implement the JSONConvertible protocol to the enum and return the rawValue between double quotes in order to avoid a JSON and a BSON error.

enum Sex: String, Codable, JSONConvertible {
    case male = "male"
    case female = "female"
    case undefined = "undefined"
    
    func jsonEncodedString() throws -> String {
        return "\"\(rawValue)\""
    }
}

I think you should speak about this in your documentation for BSON.

Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant