Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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