Skip to content

Instantly share code, notes, and snippets.

@pablocattaneo
Last active January 18, 2019 10:36
Show Gist options
  • Save pablocattaneo/f91abbf9dfdcc06d4c07c0fc4c4a9378 to your computer and use it in GitHub Desktop.
Save pablocattaneo/f91abbf9dfdcc06d4c07c0fc4c4a9378 to your computer and use it in GitHub Desktop.
.collection('collectionName').findOne({key:value})
// Example
const db = require('../db')
const ObjectId = require('mongodb').ObjectId
exports.getUser = ((req, res) => {
console.log('getUser')
filter = {
_id: new ObjectId(req.params.userId)
}
db.getDb()
.db()
.collection('usersToSendEmail')
.findOne(filter)
.then((doc) => {
res.status(200).json({doc})
})
.catch((error)=>{
console.log(error)
})
})
db.collectionName.find({key:value})
// Example
> db.usersToSendEmail.find({_id: ObjectId("5c405972f3d33522c6242d31")})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment