#Good evening,one of your expert provided me with below solution that i requested for yesterday. I tried to carryout the operation but currently my MongoDB is not work as i tried to connect using command line and compass and the deadline for the submission is this night. I really need your assistance on this to run below operations at your end and provide me with results. You can screenshot results and send it to me. Thank you. I can provide you with formated Json file if you need it to run the operation.
Here are some examples of CRUD operations that you can be perform on the "coins" collection in the "Market" database:
1.Create a new document:
db.coins.insertOne({"name": "Bitcoin", "symbol": "BTC", "price": 50000})
This command will create a new document in the "coins" collection with the specified values for the "name", "symbol", and "price" fields.
2.Read a document:
db.coins.findOne({"symbol": "BTC"})
This command will return the first document in the "coins" collection that has a "symbol" field with the value "BTC".
3.Update a document:
db.coins.updateOne({"symbol": "BTC"}, {$set: {"price": 55000}})
This command will update the "price" field of the first document in the "coins" collection that has a "symbol" field with the value "BTC".
4.Delete a document:
db.coins.deleteOne({"symbol": "BTC"})
This command will delete the first document in the "coins" collection that has a "symbol" field with the value "BTC".
5.Aggregate documents:
db.coins.aggregate([{$match: {"price": {$gte: 10000}}}, {$group: {_id: "$symbol", count: {$sum: 1}}}, {$sort: {count: -1}}])
This command will return the count of documents for each symbol in the "coins" collection where the "price" field is greater than or equal to 10000, sorted in descending order by count.
6.Indexing collection:
db.coins.createIndex({"symbol":1},{"unique":true})
This command will create a unique index on the "symbol" field, preventing the insertion of documents with duplicate "symbol" values.
7.Aggregate documents by grouping and calculating the average:
db.coins.aggregate([{$group: {_id: "$name", averagePrice: {$avg: "$price"}}}, {$sort: {averagePrice: -1}}])
This command will group the documents in the "coins" collection by their "name" field, calculate the average value of the "price" field for each group, and sort the groups in descending order by the average price.
8.Replace a document:
db.coins.replaceOne({"symbol": "BTC"}, {"name": "Bitcoin", "symbol": "BTC", "price": 55000})
This command will replace the first document in the "coins" collection that has a "symbol" field with the value "BTC" with a new document with the specified values for the "name", "symbol", and "price" fields.
9.Delete multiple documents:
db.coins.deleteMany({"price": {$lte: 100}})
This command will delete all documents in the "coins" collection where the
Here are some examples of queries that you can use:
Query 1:
SELECT name, symbol, price
FROM `myproject.mydataset.mytable`
WHERE price > 1000
ORDER BY price DESC
LIMIT 10
Explanation:
This query will return the names, symbols, and prices of the top 10 coins in the table where the price is greater than 1000, sorted in descending order by price.
Query 2:
SELECT name, COUNT(*) AS count
FROM `myproject.mydataset.mytable`
GROUP BY name
HAVING count > 1
ORDER BY count DESC
Explanation:
This query will return the names of the coins in the table and the number of times each name appears, sorted in descending order by count, but only showing those coins with a count greater than 1.
Query 3:
SELECT symbol, AVG(price) AS average_price
FROM `myproject.mydataset.mytable`
GROUP BY symbol
HAVING AVG(price) > 500
ORDER BY average_price DESC
Explanation:
This query will return the symbols of the coins in the table and their average price, sorted in descending order by average price, but only showing those coins with an average price greater than 500.