Skip to content

Instantly share code, notes, and snippets.

@robozavri
Last active September 10, 2020 10:47
Show Gist options
  • Select an option

  • Save robozavri/fab49bb34945478826cd5cb16df47a1f to your computer and use it in GitHub Desktop.

Select an option

Save robozavri/fab49bb34945478826cd5cb16df47a1f to your computer and use it in GitHub Desktop.
#mongoose
npm i mongoose
import { Schema, model, connect } from 'mongoose';
connect('mongodb://localhost:27017/monetarium', {useNewUrlParser: true, useUnifiedTopology: true});
const UserSchema = new Schema({
email: String,
fullName: String,
passwordHash: String,
});
export default model('User', UserSchema);
//////////////////////////////////////////////
const mongoose = require('mongoose');
mongoose.connect('mongodb://localhost:27017/test', {useNewUrlParser: true, useUnifiedTopology: true});
const User = mongoose.model('User', {
email: String,
fullName: String,
passwordHash: String,
});
const userDao = new User({
email: String,
fullName: String,
passwordHash: String,
});
userDao.save().then(() => console.log('created new user'));
import { Schema, model } from 'mongoose';
Reference
{
type: Schema.Types.ObjectId,
ref: 'Categories',
index: true
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment