Search By Label
brew install redis
brew services start redis
redis-cli ping
PONG
.// Custom Hook const useProducts = () => { const [products, setProducts] = useState([]); useEffect(() => { fetch("/api/products") .then((res) => res.json()) .then((data) => setProducts(data)); }, []); return products; }; // Container Component function ProductContainer() { const products = useProducts(); return <ProductList products={products} />; } // Presentational Component function ProductList({ products }) { return ( <ul> {products.map((product) => ( <li key={product.id}>{product.name}</li> ))} </ul> ); }
ed25519
algorithm to securely identify yourself:ssh-keygen -t ed25519 -C "brisamedina05@gmail.com"
eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_ed25519
cat ~/.ssh/id_ed25519.pub
mkdir project-directory cd project-directory
git clone git@github.com:your-organization/your-repository.git
cd your-repository npm install
npm run dev
sudo apt install nodejs
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash
rm -rf node_modules npm install
npm run dev
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