MongoDB Xojo Driver (maybe)

That would be sweet. I’m a busy guy as well but I would love to contribute as much as I can, especially since I’ve invested this driver into my software. I need to take some time to familiarize myself with some more of the technical details of mongo, but it definitely would be nice to see some of the more advanced features tie right into Xojo.

Ideally so we can write something technical like this:

[quote]dim cursor as MongoCursor = myCollection.find(query)._
addOption(DBQuery.Option.tailable)._
addOption(DBQuery.Option.awaitData)._
sort(sortStr)._
limit(5).toCursor
[/quote]

Sounds good.

Let met reconfigure the project the weekend, then you can always join the project on GitHub if you want to make the occasional code contribution.

PS. Others are also more than welcome to join the in if they have any feature requests…

Great dialog on this guys as I am going to need this soon :wink: Our cloud services utilize MongoDB so this is perfect timing for my Xojo app.

Thank you!

I’ve just tagged v0.3.1 of the driver on GitHub, with some of the ideas implemented.

The project is now stored in the text format, which is much more Git-friendly than using the binary format.

[quote=222202:@Brock Nash]This could be vastly improved if a few things changed.

Instead of having the cursor have a "mClient" property it would be better if it had "mCollection"
Add these accessor methods on the MongoDriver classes:

Cursor.GetCollection() as MongoCollection //Returns mCollection
Collection.GetDatabase() as MongoDatabase //Returns mDatabase
Database.GetClient as MongoClient //Returns mClient[/quote]

I’ve decided to use read-only public properties instead of methods for this:

Cursor.Collection
Collection.Database
Database.Client

So, if you have a cursor object, and want to access its collection object, simply do it as follow:

MyCursor.Collection.DoStuff()

You can now in fact access all the way up to the client object from your cursor in a single line:

MyCursor.Collection.Database.Client.DoStuff()

I trust this solves the problem of having to use introspection?

The full list of changes in v0.3.1 of the driver can be viewed on GitHub.

When my baby boy decides to give dad some time off again in the coming weeks, I’ll look into the chaining feature as discussed above.

Hi everyone,

For those of you using the MongoDB driver in your projects, “jfdemer” picked up an issue with the driver.

Here is his description of the issue:

[quote]Now, the driver as it was din’t treat accented characters correctly. The culprit is decExtractCString.
Mongo string encoding is utf-8, but decExtractCString was adding each byte to the string one by one with Chr. So all characters that are more than a single byte in utf-8 were not added correctly to the string. With my modification, the entire string is taken from the bson memory block and converted to a utf-8 string.[/quote]

I’ve merged his fix into the main trunk. You guys can just do a pull request on your side to pull down the fix to your local project.

Nice finding. I am not sure this is relevant here but since pos is passed ByRef its value should be reset if strSize was NOT > 0 don’t you think? Like in:

If strSize > 0 Then Dim s As String = DefineEncoding(bsonMB.StringValue(startPos, strSize), Encodings.UTF8) return escapeJSON(s) else pos = startPos End If

Is there new username/password support for the XOJO driver?

I have a database I need to connect to an my connection string looks like this:

mongodb://{{USERNAME}}:{{PASSWORD}}@{{WEBSITE1}}:{{PORT}},{{WEBSITE2}}:{{PORT}}/?replicaSet={{ID}}&ssl=true

Even if I can’t get the replica set part working of my connection string, I at least need to talk over SSL authenticated with username and password

I’m currently getting:

{"ok":0,"errmsg":"auth failed","code":18}

It looks like it might be related to changes in Mongo Authentication

[quote]In MongoDB 3.0, it now supports multiple authentication mechanisms.

MongoDB Challenge and Response (SCRAM-SHA-1) - default in 3.0
MongoDB Challenge and Response (MONGODB-CR) - previous default (< 3.0)
If you started with a new 3.0 database with new users created, they would have been created using SCRAM-SHA-1.[/quote]

http://stackoverflow.com/questions/18216712/cannot-authenticate-into-mongo-auth-fails
https://docs.mongodb.com/manual/release-notes/3.0-scram/#upgrade-mongodb-cr-to-scram

Hi Brock,

Nothing has changed in the driver for a long time, so if they changed the authentication method chances are that the driver as it is now won’t work.

[quote=322551:@Alwyn Bester]Hi Brock,

Nothing has changed in the driver for a long time, so if they changed the authentication method chances are that the driver as it is now won’t work.[/quote]

:frowning:

That’s what I was afraid of.
@Alwyn Bester Do you have any links to the docs/protocols you used to write the original driver. Maybe I can find a way to update it

I’m very interested in MongoDB too…

I’m in the process of launching 3 new products for my business at the moment, which requires all my devoted time, energy and focus at this point… so I unfortunately don’t have any time available to work on the MongoDB driver right now.

However, if you are willing to give the new authentication mechanism a shot, I would gladly give you full access to the GitHub repository. (Same goes for any other Xojo developer who would like to work on the MongoDB driver).

When I wrote the driver I used the official MongoDB documentation.

I did a quick search and I think the following link might be a good starting point…

https://docs.mongodb.com/manual/core/security-scram-sha-1/#authentication-scram-sha-1

It seems that SCRAM-SHA-1 is the default authentication protocol for MongoDB 3.0+. The full specification is defined in RFC5802.