Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

model mongoose

const modelName = mongoose.model("collectionname", collectionSchema);

//example
const fruitSchma = new mongoose.Schema ({
  name: String
});
const Fruit = mongoose.model("Fruit", fruitSchema);
Comment

mongoose modele

mongoose.connect('mongodb://localhost/gettingstarted', {useNewUrlParser: true,useUnifiedTopology: true});
Comment

Mongoose Model Schema

let movieSchema = mongoose.Schema({
  Title: {type: String, required: true},
  Description: {type: String, required: true},
  Genre: {
    Name: String,
    Description: String
  },
  Director: {
    Name: String,
    Bio: String
  },
  Actors: [String],
  ImagePath: String,
  Featured: Boolean
});

let userSchema = mongoose.Schema({
  Username: {type: String, required: true},
  Password: {type: String, required: true},
  Email: {type: String, required: true},
  Birthday: Date,
  FavoriteMovies: [{ type: mongoose.Schema.Types.ObjectId, ref: 'Movie' }]
});

let Movie = mongoose.model('Movie', movieSchema);
let User = mongoose.model('User', userSchema);

module.exports.Movie = Movie;
module.exports.User = User;
Comment

PREVIOUS NEXT
Code Example
Javascript :: Javascript - convert string value to lowercase 
Javascript :: inherit javascript 
Javascript :: get element by class name 
Javascript :: use font awsome in react 
Javascript :: javascript string concat vs + 
Javascript :: js event on change focus 
Javascript :: Comparing and Filtering two arrays 
Javascript :: operators in javascript 
Javascript :: axios post request javascript 
Javascript :: how to include script file in javascript with javascript 
Javascript :: js random unique id 
Javascript :: js basic user class 
Javascript :: parseint js 
Javascript :: how to pass basic auth for api in angular 11 
Javascript :: javascript get character from string 
Javascript :: setinterval in react 
Javascript :: getting values for metaboxes in wordpress 
Javascript :: How to upload an Excel sheet file using react.js and display data to a table 
Javascript :: javascript var,let,const compare 
Javascript :: remove falsy values from array with lodash 
Javascript :: accessing objects inside array 
Javascript :: how to add a letter to a string javascript 
Javascript :: javascript https post 
Javascript :: react router link with params 
Javascript :: javascript search for words in sentence examples 
Javascript :: how to remove item from array javascript 
Javascript :: search through json for key 
Javascript :: npm get package.json version 
Javascript :: express js hello world example 
Javascript :: curl send json as variable 
ADD CONTENT
Topic
Content
Source link
Name
4+9 =