Skip to content

Instantly share code, notes, and snippets.

View rohitbishnoi's full-sized avatar

rohit kumar rohitbishnoi

View GitHub Profile
@rohitbishnoi
rohitbishnoi / populateRandomeStudents.js
Created April 30, 2016 03:49
Script to populate student collection with random records
var firstNames = ['Alex', 'David', 'Peter', 'Tom', 'Shaun', 'Bill', 'Mary', 'Dan', 'Mark', 'Peter', 'Mikael', 'Sam', 'Tom', 'Fred', 'Robert', 'Martin', 'Peter'];
var lastNames = ['Michaels', 'Peterson', 'Jackson', 'Jones', 'Hank', 'Cruise', 'Radcliffe', 'Francis', 'Degroote', 'John', 'Jacobs'];
var ageList = [23,24,25,26,27,28,29,30,31,32];
var cities = ["Delhi", "London", "Paris", "Singapore", "Beijing", "Colombo", "Mumbai"];
var examTypes = ["homework", "exam", "quiz"];
var courseType = ["full time", "part time"];
function getRandom(list) {
return list[Math.floor(list.length * Math.random())];
@rohitbishnoi
rohitbishnoi / remove_lowest_score.py
Created August 22, 2016 17:27
MongoDB for Developers: Homework 3.1
from pymongo import MongoClient
def remove_lowest_score(student):
homework_scores = filter(lambda x: x['type'] == "homework", student['scores'])
all_homework_scores = map(lambda x: x['score'], homework_scores)
min_homework_score = min(all_homework_scores)
all_scores = filter(lambda x: not(x['type'] == "homework" and x['score'] == min_homework_score), student['scores'])
db.students.update_one({"_id": student["_id"]}, {"$set": {"scores" : all_scores}})
client = MongoClient()
//Calculate average age of the students
var mapFunction = function(){
emit("avgAge", this.age);
};
var reduceFunction = function(age, values){
return Array.sum(values) / values.length ;
};