Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Creating a new document
- let ciaran = new User({
- username: "ciaran",
- password: "secure"
- })
- ciaran.save()
- .then(myNewDbObject => console.log('Success!')
- .catch(err => console.log('Oops', err)
- // Find everything in a collection
- User.find().then(users => console.log(users))
- // Find one document
- User.findOne({name: "ciaran"})
- .then(user => console.log(user)
- // Update a document - can also findByIdAndUpdate(id)
- User.findOneAndUpdate(
- {name: "ciaran"}, // condition to find a record by
- {age: 21}, // update to apply
- {new: true} // return the new record
- ).then(updatedUser => console.log(updatedUser))
- // Delete a document
- User.findOneAndRemove({condition: value})
Add Comment
Please, Sign In to add comment