Horje
mongoose query foreign key Code Example
mongoose query foreign key
const mongoose = require('mongoose');

const personSchema = mongoose.Schema({
  _id: Schema.Types.ObjectId,
  name: String,
  age: Number,
  stories: [{ type: Schema.Types.ObjectId, ref: 'Story' }]
});

const storySchema = mongoose.Schema({
  author: { type: Schema.Types.ObjectId, ref: 'Person' },
  title: String,
  fans: [{ type: Schema.Types.ObjectId, ref: 'Person' }]
});

const Story = mongoose.model('Story', storySchema);
const Person = mongoose.model('Person', personSchema);

Story.
  findOne({ title: 'Casino Royale' }).
  populate('author').
  exec(function (err, story) {
    if (err) return handleError(err);
    console.log('The author is %s', story.author.name);
    // prints "The author is Ian Fleming"
  });




Javascript

Related
javascript how do I measure the time of the loop Code Example javascript how do I measure the time of the loop Code Example
how to print something in javascript Code Example how to print something in javascript Code Example
external js doesn't works if revisit the page in react Code Example external js doesn't works if revisit the page in react Code Example
what is the difference between console.log and return Code Example what is the difference between console.log and return Code Example
./src/Checkout Product.js Module not found: Can't resolve './Checkout Product.css' in '/Users/aschalew besha/Desktop/AMAZON CLONE-FRONT END/amazon clone/src' Code Example ./src/Checkout Product.js Module not found: Can't resolve './Checkout Product.css' in '/Users/aschalew besha/Desktop/AMAZON CLONE-FRONT END/amazon clone/src' Code Example

Type:
Code Example
Category:
Coding
Sub Category:
Code Example
Uploaded by:
Admin
Views:
8