Skip to content

Instantly share code, notes, and snippets.

@s9tpepper
Created July 10, 2011 00:01
Show Gist options
  • Save s9tpepper/1074076 to your computer and use it in GitHub Desktop.
Save s9tpepper/1074076 to your computer and use it in GitHub Desktop.
Authenticating with a database
function onDBConnected(db:DB):void
{
/* First create a Credentials object using your username/password */
var dbCredentials:Credentials = new Credentials("db_user_name", "db_user_password");
/* Add callback handlers for authentication problems and authenticated
Signals objects */
mongo.db("myDatabase").authenticationProblem.add(onAuthenticationProblem);
mongo.db("myDatabase").authenticated.add(onDBAuthenticated);
/* Set the credentials to the database */
mongo.db("myDatabase").setCredentials(dbCredentials);
/* Run the authenticate mongodb command */
mongo.db("myDatabase").authenticate();
}
function onAuthenticationProblem(db:DB):void
{
trace("There was a problem authenticating with the database.");
}
function onDBAuthenticated(db:DB):void
{
/*...do stuff...*/
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment