Last active
September 10, 2020 10:47
-
-
Save robozavri/fab49bb34945478826cd5cb16df47a1f to your computer and use it in GitHub Desktop.
#mongoose
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
| 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