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

Adding mongodb URL support. #80

Merged
merged 2 commits into from
Jul 30, 2012
Merged

Conversation

davideagen
Copy link
Contributor

Connections can be created with a full mongodb URL and valid mongodb urls can be parsed.

The slaveOk option has been implemented.

The rest of the features that can be specified in a mongodb:// URL (username,
password, database, multiple hosts, etc.) are not yet implemented and
warnings will be logged if attempts to use unimplemented funcationality are
made.

mongo.d changes:

connectMongoDB:
If the host field entered starts with 'mongodb://' try to construct the
MongoDB object with the URL parsing constructor. Otherwise use the
hostname/port constructor.

db.d changes:

Replaced m_host and m_port with a MongoConnectionConfig struct.
This struct holds all the configuration information that can be
specified via a mongodb:// URL.

Added a new constructor that parses a mongodb:// URL to create the
MongoConnectionConfig struct.

Modified the existing host/port constructor to instead use the host
and port to create a mongodb URL that is then passed to the new URL
constructor for processing.

Use the new MongoConnectionConfig constructor for MongoConnection
instead of the host/port constructor

connection.d changes:

Replaced m_host and m_port with a MongoConnectionConfig instance.

Added a constructor that takes a MongoConnectionConfig object.
This constructor warns (via logWarn) if features are specified in
the config that are not yet implemented.

Modified the host/port constructor to set a MongoHost instance
in the MongoConnectionConfig.

The query method has been modified to include the defQueryFlags
field of the MongoConnectionConfig struct. This implements the
new slaveOk option support.

A new function named parseMongoDBUrl (with unittest) parses a
mongodb:// URL and returns a MongoConnectionConfig object. If parsing
succeeds it returns true and false otherwise. Mongo url's are a
little different than regular URL's (multiple host/port entries, etc.)
so a dedicated parser seemed to make more sense than forcing mongo
specifics into the Url struct in url.d.

Added new structs MongoConnectionConfig and MongoHost.

…ngodb

URL and valid mongodb urls can be parsed.

The slaveOk option has been implemented.

The rest of the features that can be specified in a mongodb:// URL (username,
password, database, multiple hosts, etc.) are not yet implemented and
warnings will be logged if attempts to use unimplemented funcationality are
made.

mongo.d changes:

	connectMongoDB:
	If the host field entered starts with 'mongodb://' try to construct the
	MongoDB object with the URL parsing constructor. Otherwise use the
	hostname/port constructor.

db.d changes:

	Replaced m_host and m_port with a MongoConnectionConfig struct.
	This struct holds all the configuration information that can be
	specified via a mongodb:// URL.

	Added a new constructor that parses a mongodb:// URL to create the
	MongoConnectionConfig struct.

	Modified the existing host/port constructor to instead use the host
	and port to create a mongodb URL that is then passed to the new URL
	constructor for processing.

	Use the new MongoConnectionConfig constructor for MongoConnection
	instead of the host/port constructor

connection.d changes:

	Replaced m_host and m_port with a MongoConnectionConfig instance.

	Added a constructor that takes a MongoConnectionConfig object.
	This constructor warns (via logWarn) if features are specified in
	the config that are not yet implemented.

	Modified the host/port constructor to set a MongoHost instance
	in the MongoConnectionConfig.

	The query method has been modified to include the defQueryFlags
	field of the MongoConnectionConfig struct. This implements the
	new slaveOk option support.

	A new function named parseMongoDBUrl (with unittest) parses a
	mongodb:// URL and returns a MongoConnectionConfig object. If parsing
	succeeds it returns true and false otherwise. Mongo url's are a
	little different than regular URL's (multiple host/port entries, etc.)
	so a dedicated parser seemed to make more sense than forcing mongo
	specifics into the Url struct in url.d.

	Added new structs MongoConnectionConfig and MongoHost.
@davideagen
Copy link
Contributor Author

Existing functionality has been preserved so that code won't break with these changes.

However, one difference to note is that since the port is now passed as part of the URL string it can fail to be parsed. If that occurs (or if the URL can not be parsed for any reason) the MongoDB constructor will throw an Exception. It did not do that before.

…tion.

Also added a missing semicolon to the host/port example.
@s-ludwig
Copy link
Member

Looking good, thanks! I would just like to later rename MongoConnectionConfig to Mongo(Connection/Client/-)Settings and make it a class to be consistent with the other protocols (e.g. HttpServerSettings or SmtpClientSettings).

s-ludwig added a commit that referenced this pull request Jul 30, 2012
@s-ludwig s-ludwig merged commit bf4ea5f into vibe-d:master Jul 30, 2012
@davideagen
Copy link
Contributor Author

Ok I'll make that change in my next pull request. I think it will be fairly easy to implement support for the database portion of the URL so I'm planning to do that too.

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

Successfully merging this pull request may close these issues.

2 participants