Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using Mongo's positional operator ($) in update mutations #394

Open
LeoDupont opened this issue Nov 12, 2021 · 0 comments
Open

Using Mongo's positional operator ($) in update mutations #394

LeoDupont opened this issue Nov 12, 2021 · 0 comments

Comments

@LeoDupont
Copy link

LeoDupont commented Nov 12, 2021

Is it possible to use MongoDB's positional operator in a generated updateOne/updateMany resolver?

For example, I would like to make an update like this (from Mongo's doc):

db.students.updateOne(
   { _id: 1, grades: 80 },            # Finding the 80 value in the grades array
   { $set: { "grades.$" : 82 } }      # Replacing it by an 82
)

On my server, I've set the following generated update mutation:

// ...
schemaComposer.Mutation.addFields({
    studentUpdateOne: StudentTC.mongooseResolvers.updateOne(),
});
// ...

On my client, I've tried the following query and some others but I can't get the $ to not generate syntax errors:

mutation {
  studentUpdateOne(
    filter: {                     # Filtering works OK
      _id: 1,
      grades: 80
    },
    record: {                     # Updating throws syntax errors
      grades: { $: 82 }           # I also tried ` "grades.$": 82 ` and ` grades["$"]: 82 ` with no luck
    }
  ) {
    record {
      _id
      grades
    }
  }
}

I am not yet very familiar with GraphQL syntax so I may be missing an easy fix.
But is it at all possible?
Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant