Uploaded image for project: 'Node.js Driver'
  1. Node.js Driver
  2. NODE-1821

TypeError: Converting circular structure to JSON

    • Type: Icon: Task Task
    • Resolution: Won't Fix
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: None
    • Environment:
      Ubuntu 18.04 bionic

      hi! i encountered this error and i have no idea how to solve this: TypeError: Converting circular structure to JSON

      // this is my model
      const mongoose = require("mongoose");
      const Schema = mongoose.Schema;
      
      const User = new Schema({
        firstname: {
          type: String,
          required: true
        },
        lastname: {
          type: String,
          required: true
        },
        organisation: {
          type: String,
          required: true
        },
        address: {
          type: String,
          required: true
        },
        email: {
          type: String,
          unique: true,
          required: true,
          match: [
            /[a-zA-Z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-zA-Z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?\.)+[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?/,
            "invalid email"
          ]
        },
        status: {
          type: Boolean,
          default: false
        },
        password: {
          type: String,
          required: true
        },
        accountType: {
          type: String,
          default: 'regular',
          required: true
        },
        package: {
          type: String,
          default: 'classic',
          required: true
        }
      });
      
      module.exports = mongoose.model("User", User);
      
      
      
      User.create({
                      firstname: req.body.firstname,
                      lastname: req.body.lastname,
                      organisation: req.body.organisation,
                      address: req.body.address,
                      email: req.body.email,
                      password: hash,
                      accountType: req.body.accountType,
                      package: req.body.package
                    })
      .then(data => {
      // stuffs here gets executed and logged to console
      /* except here
      res
                        .status(201)
                        .json({
                          message: "Success! Find verification link in E-mail",
                          encData: encodedData,
                          details: doc
                        });
      */
      })
      .catch(err => {
      // this gets executed too
      res
                        .status(500)
                        .json({
                          message: err + ": Couldn't create Account"
                        });
      })
      

      At the end the document gets added. i really do not understand whats happening. It happens with both postman and angular7 on ubuntu 18.04 lts
      Thanks

            Assignee:
            Unassigned Unassigned
            Reporter:
            whizyrel Israel oluwole
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: