Last active
August 29, 2015 14:13
-
-
Save gartenfeld/38e2f6330882473803b7 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
function getQuery (searchString, callback) { | |
mongo.MongoClient.connect( | |
uri, | |
function(err, db) { | |
if(err) throw err; | |
query = { "$text": { "$search": searchString.toString() } }; | |
var cursor = db.collection("quotes").find( | |
query, | |
{ 'score': { '$meta': 'textScore' } }, | |
{ '$sort': { '$meta': 'textScore' } } | |
).limit(3); | |
cursor.toArray( | |
function(error, docs){ | |
if (docs.length === 0) { | |
callback(false); | |
} else { | |
callback(docs); | |
} } ); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment