Skip to content

Instantly share code, notes, and snippets.

View Sidheeqpallam's full-sized avatar
🎯
Focusing

Sidheeq Pallam Sidheeqpallam

🎯
Focusing
View GitHub Profile
@Sidheeqpallam
Sidheeqpallam / convertToCsv.js
Created August 25, 2022 05:12
convert an array of object to csv type data
const objectToCsv = function(data){
const csvRows =[];
//get the headers
const headers = Object.keys(data[0]);
csvRows.push(headers.join(','));
//loop over the rows
for (const row of data){
const values = headers.map(header =>{
@Sidheeqpallam
Sidheeqpallam / downloadCsv.js
Created August 25, 2022 04:44
Csv file downloading code javascript ajax
const download = function(data){
const blob = new Blob([data], {type : 'text/csv'});
const url = window.URL.createObjectURL(blob);
const a = document.createElement('a');
a.setAttribute('hidden', '');
a.setAttribute('href', url);
a.setAttribute('download', 'download.csv');
document.body.appendChild(a);
a.click();
@Sidheeqpallam
Sidheeqpallam / lookupWith_id.js
Created August 23, 2022 14:25
aggregation lookup with foreign field _id
db.getCollection('tests').aggregate([
{$match: {typet:'Req'}},
{$set: {incharge: {$toObjectId: "$incharge"} }}, // keep the whole document structure, but replace `incharge` into ObjectId
{$lookup:{
from: "users",
localField: "incharge", //this is the _id user from tests
foreignField: "_id", //this is the _id from users
as: "user"
}}
])
@Sidheeqpallam
Sidheeqpallam / customHelperCheckingTwoValues.js
Created August 22, 2022 07:47
Make a custom handlebars helper for check two values are same or not.
isEqual = (a, b, options)=>{
if(a == b){
return options.fn(this)
}
return options.inverse(this)
}