Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

128
Views
How to get reference of one schema, into another?

I have a schema, named airline schema, like this:

id:{type:Number},

name:{type:Number},

Country:{type:Number},

logo:{type:Number},

slogan:{type:Number},

head_quaters:{type:Number},

website:{type:Number},

I have to pass this schema, into another schema of passengers, like this

name:{type:String},

trips:{type:Number},

airline:??????

Now, if I fetch passengers details by its unique id given by Mongo DB, then all the details of passenger and its airline details must be seen like this

name: "Ashish"

trips:"230"

airline:[{

id:5

name:air india
.......}]

How can I do this?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

I guess each passenger used many airlines to make those trips.

So you can have the airline _ids as an array in each passenger, and do a lookup using this array.

Passenger

{name : ...
 trips : ...
 airline : [_id _id ...]   //all the airline_id he used 
}

And to combine this information you can do.
(we can use array field also as $lookup field, it will join if equal with any member)

passengers.aggregate(
[{"$lookup":
  {"from":"airline",
   "localField":"airline",
   "foreignField":"_id",
   "as":"airlines"}}])
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!