Posts

Create and drop Database and Collection

  In MongoDB, you can drop a database using the db.dropDatabase() method, and you can drop a collection using the db.collection.drop() method. Here's how you can use these commands: Drop a Collection : To drop a specific collection in MongoDB, you can use the db.collection.drop() method. Replace collection with the name of the collection you want to drop. Here's an example: use your_database_name // Switch to the appropriate database db.your_collection_name.drop() Replace your_database_name with the name of your database and your_collection_name with the name of the collection you want to drop. Drop a Database : To drop an entire database in MongoDB, you can use the db.dropDatabase() method. Be very careful when using this command because it will permanently delete the entire database and all its collections. use your_database_name // Switch to the appropriate database db.dropDatabase()

MongoDB Part2

  1.      Aggregations Exercise in MongoDB-I   AIM: To demonstrate Aggregations in MongoDB   THEORY : Aggregations operations process data records and return computed results. Aggregation operations group values from multiple documents together, and can perform a variety of operations on the grouped data to return a single result. MongoDB provides three ways to perform aggregation: the aggregation pipeline, the map-reduce function, and single purpose aggregation methods. Syntax  db.collection.aggregate(pipeline, options) Parameters Parameter Details 1.        pipeline array(A sequence of data aggregation operations or stages) 2.        options document(optional, available only if pipeline present as an array)     PROGRAM :   Example: Insert following documents in transcations collection >db.transactions.insert({ cr_dr : "D", amount : 100, fee : 2}); >db.transactions.insert({ cr_dr : "C", amount : 100, fee : 2}); >db.tra