udemy-node-todo-app/playground/mongodb-find.js
Tyrel Souza 152b6261a5 find
2017-11-29 00:35:37 -05:00

27 lines
730 B
JavaScript

// const MongoClient = require('mongodb').MongoClient;
const {MongoClient, ObjectID} = require('mongodb');
var mongoUrl = 'mongodb://127.0.0.1:27017/TodoApp';
MongoClient.connect(mongoUrl, (err, db) => {
if (err) {
return console.log('Unable to connect to MongoDB Server', err);
}
// db.collection('Todos').find().toArray().then((docs) => {
// console.log("Todos");
// console.log(JSON.stringify(docs, null, 2));
//
// }, (err) => {
// console.log("Unable to fetch todos", err);
// })
db.collection('Users').find({name: 'Tyrel'}).toArray().then((docs) => {
console.log(JSON.stringify(docs, null, 2));
}, (err) => {
console.log("Unable to fetch todos", err);
})
// db.close();
})