Data API using $merge/$out is getting 204 no content response

I am using M0 free tier shared cluster for some Mongo DB POC. I am trying to aggregate data from a Time Series collection (Events_TS )and putting the output of the aggregation pipeline into another collection(Aggreated_Events). For that, I found that The Data API needs to hit a custom HTTPS endpoint as a System user. So I have created a custom HTTPS endpoint with a function. The function looks like below

Function:-

exports = async function (request, response) {
   const mongo = context.services.get("PDCCluster");
   collection = mongo.db("PDC").collection("Events_TS");
   const pipeline =  [{
      "$group": {
        "_id": {
          "ProblemCorrelation": "$ProblemCorrelation",
          "pyTextValue(1)": {
            "$substr": [
              {
                "$cond": [
                  {
                    "$ne": ["$GeneratedDateTime", null]
                  },
                  {
                    "$toString": "$GeneratedDateTime"
                  },
                  ""
                ]
              },
              0,
              13
            ]
          },
          "RuleApplication": "$RuleApplication",
          "pyTextValue(2)": {
            "$substr": ["$requestorid", 0, 1]
          },
          "MsgID": "$MsgID",
          "ClusterName": "$ClusterName"
        },
        "pySummaryValue(1)": {
          "$sum": "$KPIValue"
        },
        "pySummaryCount(1)": {
          "$sum": 1
        }
      }
    },
    {
      "$sort": {
        "pyTextValue(1)": 1,
        "_id.ProblemCorrelation": 1,
        "_id.pyTextValue(2)": 1,
        "_id.RuleApplication": 1,
        "_id.MsgID": 1,
        "_id.ClusterName": 1
      }
    }
  ] ;
   documents = await collection.aggregate(pipeline).toArray();
   return {documents}}

URL which I am trying to hit from Data API:-

https://ap-south-1.aws.data.mongodb-api.com/app/data/endpoint/PDCAggregate

The JSON which I am trying to pass thru Data APi as requested:-

{
"collection":"Events_TS",
"database":"PDC",
"dataSource":"PDCCluster",
"pipeline": [
{
      "$match": {
        "$and": [
          {
            "GeneratedDateTime": {
              "$gte": "2023-06-01T07:00:20.435Z",
              "$lt": "2023-06-20T07:20:20.435Z"
            }
          }
        ]
      }
    },
{ "$merge" : { "into" : { "coll": "Aggreated_Events" }, "on": "_id", "whenNotMatched": "insert" } }]}

But on sending the above JSON as a request to the URL I am getting 204 no content response. Please help me out here.

Hey @Priyabrata_Nath,

Welcome to the MongoDB Community!

The 204 status code is not an error. It indicates that the server successfully processed the request, but is not returning anything.

Could you please confirm if the “Respond With Result” option is enabled in your HTTPS endpoints? This could be the reason why it is not providing any response and returning a 204 No Content status.

Also, please ensure that you test the functionality of your Atlas function to verify if it is working properly and returning the output results.

Looking forward to hearing from you.

Regards,
Kushagra

2 Likes

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.