Video 78: Querying Documents
This commit is contained in:
parent
d8617bb541
commit
e4662eb729
@ -1,7 +1,6 @@
|
||||
// CRUD create read update delete
|
||||
|
||||
const mongodb = require('mongodb')
|
||||
const MongoClient = mongodb.MongoClient
|
||||
const { MongoClient, ObjectID } = require('mongodb')
|
||||
|
||||
const connectionURL = 'mongodb://127.0.0.1:27017'
|
||||
const databaseName = 'task-manager'
|
||||
@ -13,50 +12,23 @@ MongoClient.connect(connectionURL, { useNewUrlParser: true }, (error, client) =>
|
||||
|
||||
const db = client.db(databaseName)
|
||||
|
||||
// db.collection('users').insertOne({
|
||||
// name: 'Jason',
|
||||
// age: 38
|
||||
// }, (error, result) => {
|
||||
// db.collection('users').findOne({ _id: new ObjectID('5db632720a8c580049920f36') }, (error, user) => {
|
||||
// if (error) {
|
||||
// return console.log('Unable to insert user')
|
||||
// return console.log('Unable to fetch')
|
||||
// }
|
||||
//
|
||||
// console.log(result.ops)
|
||||
// console.log(user)
|
||||
// })
|
||||
|
||||
// db.collection('users').insertMany([
|
||||
// {
|
||||
// name: 'Jen',
|
||||
// age: 28
|
||||
// },
|
||||
// {
|
||||
// name: 'Gunther',
|
||||
// age: 27
|
||||
// }
|
||||
// ], (error, result) => {
|
||||
// if (error) {
|
||||
// return console.log('Unable to insert documents')
|
||||
// }
|
||||
//
|
||||
// console.log(result.ops)
|
||||
// db.collection('users').find({ age: 38 }).toArray((error, users) => {
|
||||
// console.log(users)
|
||||
// })
|
||||
|
||||
db.collection('tasks').insertMany([
|
||||
{
|
||||
description: 'Install MongoDB',
|
||||
completed: true
|
||||
},{
|
||||
description: 'Complete the challenge for Video 76',
|
||||
completed: false
|
||||
},{
|
||||
description: 'Learn NodeJS',
|
||||
completed: false
|
||||
}
|
||||
], (error, result) => {
|
||||
if (error) {
|
||||
return console.log('Unable to insert documents')
|
||||
}
|
||||
db.collection('tasks').findOne({ _id: new ObjectID('5db5f0ef9d71180110fd3162') }, (error, task) => {
|
||||
console.log(task)
|
||||
})
|
||||
|
||||
console.log(result.ops)
|
||||
db.collection('tasks').find({ completed: false }).toArray((error, tasks) => {
|
||||
console.log(tasks)
|
||||
})
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user