Skip to content

Instantly share code, notes, and snippets.

View arahmanali's full-sized avatar
💭
Travelling is an ultimate thing to heal yourself

A Rahman Ali arahmanali

💭
Travelling is an ultimate thing to heal yourself
View GitHub Profile
///////////////////////////////////////////////////////
// $ node unique-json-parser.js [file_you_want_to_parse]
///////////////////////////////////////////////////////
var fs = require('fs');
var file_name = process.argv[2];
var obj = {}
fs.readFile(file_name + '.json', { encoding: 'utf8' }, function(err, obj) {
///////////////////////////////////////////////////////
// $ node txt-to-json-parser.js [file_you_want_to_parse]
///////////////////////////////////////////////////////
var fs = require('fs');
var arr = []
var file_name = process.argv[2];
var stream = fs.createReadStream(file_name + '.txt', { flags: 'r+', encoding: 'utf-8' });
var buf = '';
@arahmanali
arahmanali / mongoose-sum-fields.js
Last active June 19, 2022 10:08
Mongoose sum and group model's field.
/* fetch all users user_totaldocs and user_totalthings values and want to sum those variables.*/
var userSchema = mongoose.Schema({
local : {
...
...
user_id : String,
user_totaldocs : Number,
user_totalthings : Number
....
@arahmanali
arahmanali / mongoose-ref-model-service.js
Last active March 12, 2020 22:38
Mongoose nested query on Model by field by its referenced model.
/*
Find all companies that people with lastname "Robertson" have founded
*/
var mongoose = require('mongoose');
var PersonSchema = new mongoose.Schema {
firstname: String,
lastname: String
};
var Person = mongoose.model('Person', PersonSchema);