0% found this document useful (0 votes)
8 views1 page

save_filter_in10

The document contains a script that retrieves records from a database based on specific college IDs and a module name. It checks for the existence of JSON data, parses it, and updates the columns by adding new predefined column keys. Finally, it updates the database with the modified JSON data and prints the ID of each updated document.

Uploaded by

internalnpf
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views1 page

save_filter_in10

The document contains a script that retrieves records from a database based on specific college IDs and a module name. It checks for the existence of JSON data, parses it, and updates the columns by adding new predefined column keys. Finally, it updates the database with the modified JSON data and prints the ID of each updated document.

Uploaded by

internalnpf
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

let collegeIds = "6282,6284";

let collegeIdArray = collegeIds.split(',').map(id => parseInt(id.trim()));


db.saved_filter_column_list.find({
"college_id": { $in: collegeIdArray },
"module_name": "opportunity_manager",
"json_data": { $exists: true }
}).forEach(doc => {
let jsonData = JSON.parse(doc.json_data);

if (jsonData.columns && Array.isArray(jsonData.columns)) {


const newColumns = [
{ name: "column_create_keys[]", value: "u|email||Email
Address" },
{ name: "column_create_keys[]", value: "u|mobile||Mobile
Number" },
{ name: "column_create_keys[]", value: "om|stage||Stage" },
{ name: "column_create_keys[]", value: "om|created||Captured
On" }
];

jsonData.columns = [...newColumns, ...jsonData.columns];

const updatedJsonData = JSON.stringify(jsonData);

db.saved_filter_column_list.updateOne(
{ _id: doc._id },
{ $set: { json_data: updatedJsonData } }
);

print("Updated document with _id: " + doc._id);


}
});

You might also like