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

151
Views
How to get an object inside another object?

This is my collection like,

[
   {
      "column1":"data1",
      "column2":"data2",
      "column3":[
         {
            "column31":"data31",
            "column32":"data32"
         }
      ],
      "column4":"data4"
   },
   {
      "column1":"data11",
      "column2":"data22",
      "column3":[
         {
            "column31":"data312",
            "column32":"data322"
         }
      ],
      "column4":"data44"
   }
]

I want to get columns which has 'column1 : "data11"' and 'column31 : "data312"'

This is my query, but it returns null object

    collection.find({
        column1: "data11",
        column3: {
            column31 : "data312"
        }
    }).then((item)=>{
        res.json(item);
    }).catch((err)=>{
        console.log(err);
    });

How can I fix this issue?

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

0

You have to use dot notation, otherwise you are telling mongo that matches the entire object.

So this query works:

db.collection.find({
  "column1": "data11",
  "column3.column31": "data312"
})

Example here

about 4 years ago · Juan Pablo Isaza Report

0

Change your query like this:

collection.find({
    column1: "data11",
    "column3.column31": "data312"
}).then((item)=>{
    res.json(item);
}).catch((err)=>{
    console.log(err);
});
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!