Skip to content

Instantly share code, notes, and snippets.

View AllStackDev1's full-sized avatar
🏠
Working from home

Chinedu Ekene Okpala AllStackDev1

🏠
Working from home
View GitHub Profile
@AllStackDev1
AllStackDev1 / getHistory.js
Created December 3, 2018 18:22
Trying to get user history of my app
// I use passport as auth so req.user is set by it.
// Is this code feasible enough when the user has many farms with different crops, i.e when the user data grows
// As of now the code taken up to 1412 ms to complete
const { Farm } = require('../models/farm');
getHistory = function(req, res, next) {
Farm.find().distinct('cropId', { userId: req.user._id }, (err, cropIds) => {
if (err) return res.send({ success: false, err });
let i = 0;
let data = [];