GithubHelp home page GithubHelp logo

ms-for-ironhack / week4_day5 Goto Github PK

View Code? Open in Web Editor NEW

This project forked from bootcamp-webmad-0122/week4_day5

0.0 0.0 0.0 66 KB

Fullstack app, model relationships

JavaScript 83.20% CSS 0.82% Handlebars 15.99%

week4_day5's Introduction

week4_day5

Express & Mongoose | Create & update documents, Document relationships

Node | Basic Authorization, Autentication & Sessions

Main points: document relationships (populating)

Para relacionar documentos:

  • En el modelo: indicar en la propiedad a relacionar type: Schema.Types.ObjectId y ref: 'nombreModelo':
    const thingSchema = new Schema({
      title: String,
      owner: { type : Schema.Types.ObjectId, ref: 'User' },     // 'User' es el nombre del modelo
      price: Number
    })
  • En el controlador: para popular una consulta a la BBDD, requerir el modelo populado y pasar como argumento a .populate() el nombre del campo que contiene la referencia a oltra colección:
    require('../models/owner.model')
    
    Thing.find()
      .populate('owner')    // 'owner' es el nombre del campo del modelo 'thing'
      .then(thing => console.log(thing))

week4_day5's People

Contributors

german-alvarez-dev avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.