Skip to content

Instantly share code, notes, and snippets.

@gartenfeld
Last active August 29, 2015 14:13
Show Gist options
  • Save gartenfeld/38e2f6330882473803b7 to your computer and use it in GitHub Desktop.
Save gartenfeld/38e2f6330882473803b7 to your computer and use it in GitHub Desktop.
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