Skip to content

Instantly share code, notes, and snippets.

@rbcmgs
Created September 15, 2022 17:16
Show Gist options
  • Select an option

  • Save rbcmgs/7de92f99ff166430ec405702a483cfed to your computer and use it in GitHub Desktop.

Select an option

Save rbcmgs/7de92f99ff166430ec405702a483cfed to your computer and use it in GitHub Desktop.
javascript mongoose return fields selectively
const User = require("./model/User");
// Return documents excluding fields
const excluding = await User
.find()
.select("-pass -salt");
console.log("Data excluding fields:", excluding);
// Return documents including fields
const including = await User
.find()
.select("pass salt");
console.log("Data including fields:", including);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment