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

295
Views
project some fields in $lookup mongodb

https://docs.mongodb.com/manual/reference/operator/aggregation/lookup/

Whole document is written to the "inventory_docs" field. Is there any way to shrink or $project the document which is going to written to "inventory_docs"

db.orders.aggregate([{
  $lookup: {
    from: "inventory",
    localField: "item",
    foreignField: "sku",
    as: "inventory_docs"
  }
}])

What I am saying is, rather than this;

{
  "_id": 1,
   "item": "abc",
  "price": 12,
  "quantity": 2,
  "inventory_docs": [
    { "_id": 1, "sku": "abc", description: "product 1", "instock": 120 }
  ]
}

I want to create it as;

{
  "_id": 1,
  "item": "abc",
  "price": 12,
  "quantity": 2,
  "inventory_docs": [
    { "_id": 1, "instock": 120 }
  ]
}

How can I do it?

over 4 years ago · Santiago Trujillo
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!