最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

使用Mongoose和Node.js从mongoDB检索数据时出错

运维笔记admin10浏览0评论

使用Mongoose和Node.js从mongoDB检索数据时出错

使用Mongoose和Node.js从mongoDB检索数据时出错

我使用Node.js和Mongoose从MongoDB获取记录时收到以下错误。

错误:

TypeError: Converting circular structure to JSON
    at JSON.stringify (<anonymous>)
    at stringify (/home/subrajyoti/Desktop/landing/node_modules/express/lib/response.js:1064:12)

以下是在下面的集合中插入的文档格式。

{
          zone_list: [{
            zone: NORTH,
            state_list: [{    
              state: DELHI,
              location_list: [{
                location: NEW DELHI,
                task_list: [{
                  user_pkId: 5c407834953d7f420d56f866,
                  front_end_manager_name: SONAL,
                  collection_manager: "",
                  area_collection_manager: ASHIS JENA,
                  loan_accounts_assigned: [{
                    allocated_to: FIELD,
                    lk_loan_account_id: LK0000015094,
                    cl_contract_id: LAI-00016881,
                    customer_name: REET INFOTECH,
                    customer_bank_name: YES BANK,
                  }]
                }]
              }]
            },{
              state: JK,
              location_list: [{
                location: Sree Nagar,
                task_list: [{
                  user_pkId: 5c407834953d7f420d56f867,
                  front_end_manager_name: SONAL,
                  collection_manager: "",
                  area_collection_manager: ASHIS JENA,
                  loan_accounts_assigned: [{
                    allocated_to: FIELD,
                    lk_loan_account_id: LK0000015094,
                    cl_contract_id: LAI-00016881,
                    customer_name: REET INFOTECH,
                    customer_bank_name: Corporate BANK,
                  }]
                }]
              }]
            }]
          },{
            zone: EAST,
            state_list: [{    
              state: Odisha,
              location_list: [{
                location: Bhubaneswar,
                task_list: [{
                  user_pkId: 5c407834953d7f420d56f868,
                  front_end_manager_name: SONAL,
                  collection_manager: "",
                  area_collection_manager: ASHIS JENA,
                  loan_accounts_assigned: [{
                    allocated_to: FIELD,
                    lk_loan_account_id: LK0000015094,
                    cl_contract_id: LAI-00016881,
                    customer_name: REET INFOTECH,
                    customer_bank_name: SBI BANK,
                  }]
                }]
              }]
            }]
          }]
        }

我使用以下查询。

var allction = db.model("Allocation", alloc);
    allction.collection.aggregate([
       {
          $project: {
             zone_list: {
                $filter: {
                   input: "$zone_list",
                   as: "zonelist",
                   cond: { $gte: [ "$$zonelist.zone", zoneInput ] }
                }
             }
          }
       }
    ],function(err,docs){
        if (!err) {
            res.send(docs);
        }else{
            res.send(err);
        }
    })

在这里,我需要根据zonezone and state等获取记录。

回答如下:

allction.collection返回Allocation模型使用的集合。 https://mongoosejs/docs/api.html#model_Model-collection

快速修复,只需使用allction.aggregate而不是allction.collection.aggregate

发布评论

评论列表(0)

  1. 暂无评论