Home > front end >  Object Query in MongoDB - Compass
Object Query in MongoDB - Compass

Time:11-10

I'd like to execute an object query about how many documents have "JAVA" in the variable L5_tecnologias:

Screenshot with the data structure of variable L5_tecnologias

As you can see in the screenshot, I use the formula shown in the MongoDB manual (https://docs.mongodb.com/manual/tutorial/query-embedded-documents/), but it does not work. So I've tried the commands:

{ L5_tecnologias: { JAVA: "" } }
{ L5_tecnologias: ["JAVA"] }y
{ L5_tecnologias: "JAVA" } 

but none of them work. Anyone can help?

CodePudding user response:

Use dot notation with $exists.

db.collection.find({
  "L5_tecnologias.JAVA": {
    $exists: true
  }
})

Sample Mongo Playground

  • Related