Created
September 15, 2022 17:16
-
-
Save rbcmgs/7de92f99ff166430ec405702a483cfed to your computer and use it in GitHub Desktop.
javascript mongoose return fields selectively
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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