Skip to content

Instantly share code, notes, and snippets.

@barmgeat
Created June 27, 2019 17:49
Show Gist options
  • Save barmgeat/3dbf21bafaf9f30fd7f26e6d5e4979bf to your computer and use it in GitHub Desktop.
Save barmgeat/3dbf21bafaf9f30fd7f26e6d5e4979bf to your computer and use it in GitHub Desktop.
var userSchema = mongoose.Schema({
"id": Number,
"username": String,
"paswod": String,
"name": String,
"last_name": String
});
var user = mongoose.model('users', userSchema);
// to fetch all users
user.find(function (err, user) {
if (err) return console.error(err);
console.log(user);
});
// to get specific user
user.find({ name: /^mmustafa/ }, function (err, user) {
if (err) return console.error(err);
console.log(user);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment