Skip to content

Filter on subdocument property #192

Open
@kaboume

Description

@kaboume

Hi,

// Stage Schema
const stageSchema = mongoose.Schema(
  {
    ...
    federation: federationSchema,
    ...
// Subdocument Schema
const federationSchema = mongoose.Schema({
  nom: {
    type: String,
    required: true,
    trim: true,
  },
  groupeId: {
    type: mongoose.ObjectId,
    ref: 'Groupe',
    required: false,
  },
  type: {
    type: String,
    required: false,
  },

});

I want to select all the stages that have a name of federation equal to "toto"
So I tried :

const filter = {}
filter.federation = { stage: 'toto'}
..
await Stage.find(filter).

But 0 stages are returned...
Is my filter correct ?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions