'How to restrict text in one column if the text is having multiple commas while generating csv throigh mongo command
In the JSON commas were there in the remarks column text so when we execute mongo command ,in the csv file ,remarks was going to the multiple cells.Can we restrict whole remarks column should be in one cell?
mongo dbEntityDB dbEntity.js > out.csv
db.dbEntity.insertOne(
{
"employee": {
"employeeId": "46363366",
"name": "wrwr",
"remarks": "abcd,efgh"
}
}
)
dbEntity.js
************
print("employeeId,name,remarks");
cursor=db.dbEntity.find();
let out="";
while(cursor.hasNext()){
jsonobj=cursor.next();
employeeId = jsonobj.employee.employeeId;
name = jsonobj.employee.name;
remarks = jsonobj.employee.remarks;
out =out+ employeeId +","+name +","+customerName+","+remarks+"\n";
};
print(out)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
