Skip to content

Instantly share code, notes, and snippets.

@s9tpepper
Created July 10, 2011 01:18
Show Gist options
  • Save s9tpepper/1074128 to your computer and use it in GitHub Desktop.
Save s9tpepper/1074128 to your computer and use it in GitHub Desktop.
Using the insert() method
/* Use a Document object to build the BSON document to save into the database */
const newDocument:Document = new Document();
newDocument.put("name", "Hello from Flash sucka!");
/* Use the insert() method to save. This method does not return anything */
mongo.db("myDatabase").collection("myCollection").insert(newDocument);
/* Use a getLastError command to get the status of the last insert attempt. */
mongo.db("myDatabase").runCommand(new Document("getLastError:")).addOnce(onLastError);
function onLastError(opReply:OpReply):void
{
// The command response document will be in the first element
// of the documents Array in the OpReply object. The structure
// of the document will depend on the command executed.
var document:Object = opReply.documents[0];
// The ok property should equal 1 if the insert was a success.
if (1 == document.ok)
{
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment