Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

224
Views
Specifying a condition when sending payload Axios and Mongoose

Accounts model:

let accountsSchema = new mongoose.Schema({
    posts:{
        type: Array
    }
});

const Post = mongoose.model("Account", postSchema);

postController in Posts Microservice:

 let myAccountPosts = await axios.get(`${process.env.ACCOUNTS_MICROSERVICE_URL}/router/account/${userID}`)
.then((resp) => {

    resp.data.message.map((account) =>{


        account.posts.map((post) =>{


            if(myUserPostID !== post._id){



        //the following resets the entire posts array in the other microservice, consider resetting/deleting only that particular post
                let deletePostFromAccountsMicroservice = axios.patch(`${process.env.ACCOUNTS_MICROSERVICE_URL}/router/account/update/${userID}`, {"posts.$[]": "abc"}, (err) =>{
                    if(err) return err;
                });


            }else{
                console.log("no")

            }

        });

    });
}).catch((err) =>{
    console.log("err: ", err.message);
    return err;
});

This is what the response looks like:

{
  posts:[{_id:'6290ed85716a08d29dab3aa5'}, { _id: '1234ed85716a08d29b35342' } ]
} 

In the following line of code:

let deletePostFromAccountsMicroservice = axios.patch(`${process.env.ACCOUNTS_MICROSERVICE_URL}/router/account/update/${userID}`, {"posts.$[]": "abc"}, (err) =>{
    if(err) return err;
});

I want the posts.$[] to target only the object that has an _id that matches this condition (myUserPostID !== post._id)

How do achieve that?

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!