Next.js Discord

Discord Forum

Moving to Data API

Answered
Barbary Lion posted this in #help-forum
Open in Discord
Barbary LionOP
I want to move this piece of code to mongodb data api
const doc = await users.findOneAndUpdate(
      {
        email: session.user.email,
        campaigns: {
          $elemMatch: {
            id
          },
        },
      },
      {
        $push: {
          "campaigns.$.leads": {
            $each: [...leads],
          },
        },
      }
    );

How do I do that?
Answered by Anay-208
The option is to run findOne and update seperately
View full answer

21 Replies

Barbary LionOP
@Anay-208 can you help?
there isn't a find one and update on data api endpoints
sure
let me open my editor real quick and check
Barbary LionOP
yh thanks
I'll give you a solution tomorrow
after 13-14 hours
Barbary LionOP
I think I got it man
But I'll check back with you if I haven't
The option is to run findOne and update seperately
Answer
thats the only option
@Barbary Lion
Barbary LionOP
Got it man
@Anay-208 The option is to run findOne and update seperately
Barbary LionOP
That's what I'm doing
alr, can you mark answer as a solution
Barbary LionOP
Just did update
Worked
oh ya
@Anay-208 The option is to run findOne and update seperately
can you mark this answer as a solution?
Barbary LionOP
@Anay-208 done
Thanks