Created
July 10, 2011 00:30
-
-
Save s9tpepper/1074094 to your computer and use it in GitHub Desktop.
Using the findOne() method
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* The findOne() method will take a query and return a single document. The | |
query is built using the Document class. If no second argument is used in | |
the find() one method all fields are returned for the document. */ | |
var query:Document = new Document("fieldName:searchValue"); | |
mongo.db("myDatabase").collection("myCollection").findOne(query).addOnce(findOneReply); | |
/* Returned fields can be limited by using the return fields document. */ | |
var returnFields:Document = new Document("fieldName:1"); | |
var query:Document = new Document("fieldName:searchValue"); | |
mongo.db("myDatabase").collection("myCollection").findOne(query, returnFields) | |
.addOnce(findOneReply); | |
/* The callback handler must expect a FindOneResult object */ | |
function findOneReply(findOneResult:FindOneResult):void | |
{ | |
// The success property is true if a document is retrieved. | |
if (true == findOneResult.success) | |
{ | |
// The document property will contain the document found. | |
var myDoc:Object = findOneResult.document; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment