0% found this document useful (0 votes)
4 views4 pages

Program-7 Dbms Lab

The document outlines the process of creating and managing a MongoDB collection named 'ProgrammingBooks'. It includes inserting multiple book entries, updating an author's name, querying books based on publication year, and performing delete operations. Finally, it demonstrates dropping the collection after deleting all documents within it.

Uploaded by

harini.aimlfac
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views4 pages

Program-7 Dbms Lab

The document outlines the process of creating and managing a MongoDB collection named 'ProgrammingBooks'. It includes inserting multiple book entries, updating an author's name, querying books based on publication year, and performing delete operations. Finally, it demonstrates dropping the collection after deleting all documents within it.

Uploaded by

harini.aimlfac
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Prog-7

mongosh
test> use bookDB
switched to db bookDB
bookDB> set (0.00 sec)

bookDB> [Link]("ProgrammingBooks")
go to cmd prompt press right mouse button n enter
bookDB> [Link]([
{
title: "Clean Code: A Handbook of Agile Software Craftsmanship",
author: "Robert C. Martin",
category: "Software Development",
year: 2008
},
{
title: "JavaScript: The Good Parts",
author: "Douglas Crockford",
category: "JavaScript",
year: 2008
},
{
title: "Design Patterns: Elements of Reusable Object-Oriented Software",
author: "Erich Gamma, Richard Helm, Ralph Johnson, John Vlissides",
category: "Software Design",
year: 1994
}
])

bookDB> [Link]().pretty()
[
{
_id: ObjectId('663eaaebae582498972202df'),
title: 'Clean Code: A Handbook of Agile Software Craftsmanship',
author: 'Robert C. Martin',
category: 'Software Development',
year: 2008
},
{
_id: ObjectId('663eaaebae582498972202e0'),
title: 'JavaScript: The Good Parts',
author: 'Douglas Crockford',
category: 'JavaScript',
year: 2008
},
{
_id: ObjectId('663eaaebae582498972202e1'),
title: 'Design Patterns: Elements of Reusable Object-Oriented Software',
author: 'Erich Gamma, Richard Helm, Ralph Johnson, John Vlissides',
category: 'Software Design',
year: 1994
}
]

bookDB>[Link](
{ title: "Clean Code: A Handbook of Agile Software Craftsmanship" },
{ $set: { author: "Robert C. Martin (Uncle Bob)" } }
)

//verify by displaying books published in year 2008


bookDB> [Link]({ year: { $eq: 2008 } }).pretty()
[
{
_id: ObjectId('663eaaebae582498972202df'),
title: 'Clean Code: A Handbook of Agile Software Craftsmanship',
author: 'Robert C. Martin (Uncle Bob)',
category: 'Software Development',
year: 2008
},
{
_id: ObjectId('663eaaebae582498972202e0'),
title: 'JavaScript: The Good Parts',
author: 'Douglas Crockford',
category: 'JavaScript',
year: 2008
}
]

//verify the update operation by displaying books published before year 2010
bookDB> [Link]({ year: { $lt: 2010 } }).pretty()
[
{
_id: ObjectId('663eaaebae582498972202df'),
title: 'Clean Code: A Handbook of Agile Software Craftsmanship',
author: 'Robert C. Martin (Uncle Bob)',
category: 'Classic Programming Books',
year: 2008
},
{
_id: ObjectId('663eaaebae582498972202e0'),
title: 'JavaScript: The Good Parts',
author: 'Douglas Crockford',
category: 'Classic Programming Books',
year: 2008
},
{
_id: ObjectId('663eaaebae582498972202e1'),
title: 'Design Patterns: Elements of Reusable Object-Oriented Software',
author: 'Erich Gamma, Richard Helm, Ralph Johnson, John Vlissides',
category: 'Classic Programming Books',
year: 1994
}
]

bookDB> [Link]({ title: "JavaScript: The Good Parts"


})
{ acknowledged: true, deletedCount: 1 }

//delete all documents in a collection


bookDB> [Link]({})
{ acknowledged: true, deletedCount: 3 }

//verify by displaying the collection


bookDB> [Link]().pretty()
bookDB> show collections
ProgrammingBooks

bookDB> [Link]()
true

bookDB> show collections

bookDB>

You might also like