Skip to content

Instantly share code, notes, and snippets.

@lyzs90
Last active December 14, 2016 17:22
Show Gist options
  • Select an option

  • Save lyzs90/8cfc746ebe4d9c8d3f01d0ee5861e667 to your computer and use it in GitHub Desktop.

Select an option

Save lyzs90/8cfc746ebe4d9c8d3f01d0ee5861e667 to your computer and use it in GitHub Desktop.
// Count Query
MongoClient.connectAsync(uri)
.then((db) => {
return db.collection(collection).countAsync(session.userData.selector);
})
.then((count) => {
console.log(`Success: Total of ${count} records`);
session.userData.count = count;
})
.catch((err) => {
throw err;
});
// Find Query
MongoClient.connectAsync(uri)
.then((db) => {
return db.collection(collection).findAsync(session.userData.selector, {
'limit': 5,
'skip': session.userData.cursor
});
})
.then((cursor) => {
return cursor.toArrayAsync();
})
.then((arr) => {
let tmpDeck = [];
createDeck(session, tmpDeck, arr, 5);
let msg = new builder.Message(session)
.attachmentLayout(builder.AttachmentLayout.carousel)
return session.send(msg);
})
.then(() => {
session.userData.cursor += 5;
return session.replaceDialog('moreResults:/');
})
.catch((err) => {
throw err;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment