Mongoose aggregation With GraphQL returning error

Viewed 25

I'm working on a project and currently using Mongodb Time-Series and aggregation. I connected my Apollo Graphql to retrieve the data but i'm stuck with an error that i can not solve no matter what.

Float cannot represent non numeric value:

On my db the numbers are saved as Double. If i try to run the query in MongoDB Aggregation with MongoDBCompass it's working perfectly but not on my Nodejs database.

I tried googling my problem first and looking ad docs but all the different solution i found do not solve my problem, any suggestions?

This is my Query:

module.exports = async (root, { limit }, { models }) => {

  const keyx = await models.Weather.aggregate([
    {
      $group: {
        _id: {
          yearMonthDay: {
            $dateToString: { format: "%Y-%m-%d", date: "$timestamp" },
          },
        },
        temp: {
          $push: { temp: "$temp" },
        },
      },
    },
  ])
    .exec();

  return keyx;
};

This is my model:

const mongoose = require("mongoose");

const { Schema } = mongoose;
mongoose.pluralize(null);

const weather = new Schema({
  timestamp: {
    type: String,
    trim: true,
  },
  temp: {
    type: Number,
    trim: true,
  },
 
});

const Weather = mongoose.model("time_weather", weather);
module.exports = { Weather };

and this is my types:

const { gql } = require("apollo-server");

module.exports = gql`
  type Weather {
    timestamp: String
    _id: ID
    temp: Float
    
  }

  type Query {
    weather(limit: Int): [Weather]
  }
`;

and finally this is the response i'm getting from apollo studio:

{
  "errors": [
    {
      "message": "Float cannot represent non numeric value: [{ temp: 11.7 }, { temp: 11.7 }, { temp: 12.01 }, { temp: 13.21 }, { temp: 13.21 }, { temp: 11.93 }, { temp: 13.21 }, { temp: 12.73 }, { temp: 14.21 }, { temp: 11.7 }, ... 14 more items]",
      "locations": [
        {
          "line": 6,
          "column": 5
        }
      ],
      "path": [
        "weather",
        0,
        "temp"
      ],
      
      }
    },
0 Answers
Related