vadimdemedes / mongorito

🍹 MongoDB ODM for Node.js apps based on Redux
1.38k stars 90 forks source link

How to use inherited(?) mquery findOneAndUpdate method #203

Closed adieuadieu closed 6 years ago

adieuadieu commented 6 years ago

Hello @vadimdemedes. Thanks for this neat project!

How can I use the findOneAndUpdate() method that's inherited from mquery?

Or, is this not possible because findOneAndUpdate doesn't fall into the category of a query-condition methods (like all() or and(), but rather a query-method ..method (like find(), distinct()), which must be implemented in mongorito itself?

I can do it like this, but it seems like abuse (and the result is not an instance of the Mongorito model):

const blah = MyFancyModel.findOneAndUpdate(
  { something: 'somevalue' },
  { somethingElse: 'some other value' },
  { upsert: true }
)

const result = await MyFancyModel.query('findOneAndUpdate', blah.query)

or more specifically:


const result = await MyFancyModel.query('findOneAndUpdate', [
  [
    'findOneAndUpdate',
    [
      { something: 'somevalue' },
      { somethingElse: 'some other value' },
      { upsert: true }
    ],
  ]
])
vadimdemedes commented 6 years ago

Hey, thanks! To use this method it has to be added to these 2 files:

Would you be interested in making a PR for it?

adieuadieu commented 6 years ago

Thanks @vadimdemedes! I'll raise a PR.

adieuadieu commented 6 years ago

@vadimdemedes I've raised PR #210 for this.