在使用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);
}
})
在这里,我需要按照zone
或zone and state
等来获取记录。
答案 0 :(得分:0)
allction.collection
返回Allocation
模型使用的集合。
https://mongoosejs.com/docs/api.html#model_Model-collection
快速修复,只需使用allction.aggregate
而不是allction.collection.aggregate