I have one requirement to send MongoDB collection data in chunks from one microservice to another microservice by calling POST API
so, I tried this
microservice - A (Accept data and store in db)
app.post("/savedata", async(req, res) => {
console.log("Body => %o", req.body);
// insert data into db
res.status(200).send({status: "ok"});
});
microservice - B (Get data from mongo and post to microservice-A)
app.post("/postdata", async(req, res) => {
let db = await client.db("Student");
let collection = db.collection("details");
let query = [
{
"$project": {
_id:0
}
}
];
let mongoStream = collection.aggregate(query).stream();
const url = "http://microservice_A_HOST/savedata";
axios({
url: url,
method: "post",
data: mongoStream,
headers: {
'Content-Type': 'application/json'
}
}).then((response) => {
console.log("Resp %j =>", response.status);
}).catch(err => {
console.log("err => ", err);
});
res.status(200).send({status: "ok"});
});
I am getting this error
TypeError: data should be a string, Buffer or Uint8Array
at RedirectableRequest.write (/root/sample_code/node_modules/follow-redirects/index.js:84:11)
at AggregationCursor.ondata (_stream_readable.js:726:22)
at AggregationCursor.emit (events.js:210:5)
at addChunk (_stream_readable.js:308:12)
at readableAddChunk (_stream_readable.js:289:11)
at AggregationCursor.Readable.push (_stream_readable.js:223:10)
please help me out Thanks