Created
June 16, 2018 20:59
-
-
Save deslee/8a32036030c15c189edde1fd9b8cb449 to your computer and use it in GitHub Desktop.
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
getRandomPun(): Promise<Pun> { | |
return this.client.db('punbot').collection('puns').aggregate([ | |
{ '$sample': { 'size': 1 } } | |
]).toArray().then(result => { | |
if (result.length) { | |
return result[0]; | |
} | |
return undefined; | |
}).catch(err => { | |
console.error(err); | |
}); | |
} | |
getSpecificPun(query: string): Promise<Pun[]> { | |
return this.client.db('punbot').collection('puns') | |
.find( | |
{ '$text': { '$search': query } } | |
) | |
.project( | |
{ 'text': 1, 'score': { '$meta': 'textScore' } } | |
) | |
.sort({ 'score': { '$meta': 'textScore' } }) | |
.toArray().then(result => { | |
return result; | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment