Search By Label
orders
with documents representing individual orders. Each document has fields like order_id
, customer_id
, product_name
, and price
. We want to calculate the average order value for each customer.db.orders.aggregate([ { $group: { _id: "$customer_id", total_spent: { $sum: "$price" }, total_orders: { $count: {} } } }, { $project: { average_order_value: { $divide: ["$total_spent", "$total_orders"] } } } ])
customer_id
.$sum
.$count
.total_spent
by total_orders
.customer_id
and the calculated average_order_value
.mongosh "mongodb+srv://{MONGO_COLLECTION_USER}:{MONGO_COLLECTION_PASSWORD}@{MONGO_APP_NAME}.yng1j.mongodb.net/?appName={MONGO_APP_NAME}"
// show databases show dbs // use database use <db_name> // show collections show collections // finally interact with them, for example db.users.findOne()
CREATE PROCEDURE GetCustomers AS BEGIN SELECT CustomerID, CustomerName, City FROM Customers; END; // How to use? EXEC GetCustomers;
CREATE PROCEDURE GetCustomersByCity @City nvarchar(50) AS BEGIN SELECT CustomerID, CustomerName FROM Customers WHERE City = @City; END; // How to use? EXEC GetCustomersByCity @City = 'London';
Date
.db.sessions.createIndex({ expiresAt: 1 }, { expireAfterSeconds: 3600 });
expiresAt
field and sets the TTL to 1 hour (3600 seconds). Any documents in the sessions
collection with an expiresAt
value that is older than 1 hour will be automatically deleted.explain("executionStats")
command in MongoDB provides detailed information about the execution plan and performance metrics of a query.find()
method, it returns a document containing statistics about how MongoDB executed the query.db.products.explain("executionStats").find({ price: { $gt: 10 } });
from
: The collection to use for lookup in the same databaselocalField
: The field in the primary collection that can be used as a unique identifier in the from
collection.foreignField
: The field in the from
collection that can be used as a unique identifier in the primary collection.as
: The name of the new field that will contain the matching documents from the from
collection.db.comments.aggregate([
{
$lookup: {
from: "movies",
localField: "movie_id",
foreignField: "_id",
as: "movie_details",
},
},
{
$limit: 1
}
])
let original = { a: 1, b: { c: 2 } } let copy = { ...original } copy.b.c = 3 // Changes "original.b.c"
let original = { a: 1, b: { c: 2 } } let copy = JSON.parse(JSON.stringify(original)); copy.b.c = 3 // The "original.b.c" remains 2
debugger;
statement where you want to insert a break point$ node inspect <file name>
c
to continue to next break pointrepl
. For more information, Please check the official guide.
Amazon Textract is a machine learning (ML) service that automatically extracts text, handwriting, design elements and data from scanned documents. It goes beyond simple optical character recognition (OCR) to identify, understand and extract specific data from documents.