0

I did these two models and i have no idea how to make connection between food and user.

model 1:

const mongoose = require('mongoose');
const passportLocalMongoose = require('passport-local-mongoose');


var UserSchema = new mongoose.Schema({
    username: String,
    password: String,
    repassword: String,
    email: String

})

UserSchema.plugin(passportLocalMongoose);

module.exports = mongoose.model("User", UserSchema);

model 2:

var mongoose = require('mongoose');


var foodSchema = new mongoose.Schema({
   name: String,
   image: String,
   notify: String,
   createdAt: {type: Date, default: Date.now},
    author: {
      id: {
         type: mongoose.Schema.Types.ObjectId,
         ref: "User"
      },
      username: String
   },
});


   module.exports = mongoose.model("food", foodSchema);
  • To query out the data can you try `populate` – vizsatiz Jul 08 '18 at 10:41
  • Possible duplicate of [how to join multiple collections with $lookup mongodb](https://stackoverflow.com/questions/35813854/how-to-join-multiple-collections-with-lookup-mongodb) – Ashh Jul 08 '18 at 10:41

0 Answers0