{"size": 1205, "ext": "js", "max_stars_repo_path": "playground/mongodb-find.js", "max_stars_repo_name": "Abhimanyu10/TodoApp", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "playground/mongodb-find.js", "max_issues_repo_name": "Abhimanyu10/TodoApp", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "playground/mongodb-find.js", "max_forks_repo_name": "Abhimanyu10/TodoApp", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 26.7777777778, "max_line_length": 93, "alphanum_fraction": 0.5917012448}
//const MongoClient = require('mongodb').MongoClient;
const {MongoClient, ObjectId} = require('mongodb')
//var obj = new ObjectId();
//console.log(obj);


MongoClient.connect('mongodb://localhost:27017/TodoApp',(err , client)=>{
	if(err){
		console.log(err);
		return console.log('unable to connect to mongodb');	
		
	}


	console.log('Connected to MongoDB server');
	const db = client.db('TodoApp');
    db.collection('Todos').find().toArray().then(docs=> {
        console.log('Todos')
        console.log(JSON.stringify(docs , undefined , 2));
    }, (err) => { 
        console.log('Unable to fetch todos');
    });

    db.collection('Todos').find({ completed: false }).toArray().then(
        (docs)=>{
            console.log('Todos');
            console.log(JSON.stringify(docs, undefined, 2));
        }, (err) => {
            console.log('Unable to fetch todos', err);
        }    
    );
    //find returns mongodb cursor 

    db.collection('Todos').find({
        _id : new ObjectId("5e4fb98b1407172e5064ba8f")
    }).toArray().then((docs) => { console.log(JSON.stringify(docs,undefined , 2))},(err) => {
        console.log('Unable to fetch todos', err);
    });

	client.close();
});



