Skip to content

Instantly share code, notes, and snippets.

@parkerfoshay
Created July 24, 2023 21:54
Show Gist options
  • Save parkerfoshay/b11972c875929e363ed966a318a67345 to your computer and use it in GitHub Desktop.
Save parkerfoshay/b11972c875929e363ed966a318a67345 to your computer and use it in GitHub Desktop.
mdb-vs-l4
const database = "inventory";
const collection = "products";
const fs = require('fs');
use(database);
db.products.drop();
db.createCollection(collection);
const productsData = [
{name: "Smartphone", price: 499.99, category: "Electronics", description: "A high-end smartphone with advanced features.", inStock: true, colors: ["Black", "Silver", "Gold"]},
{name: "Laptop", price: 899.95, category: "Electronics", description: "A powerful laptop for both work and entertainment.", inStock: true, colors: ["Silver", "Space Gray"]},
{name: "Running Shoes", price: 89.99, category: "Sports", description: "Comfortable and lightweight shoes for running and training.", inStock: false, colors: ["Black", "White", "Red"]},
{name: "Wireless Earbuds", price: 79.99, category: "Electronics", description: "True wireless earbuds with noise-cancellation technology.", inStock: true, colors: ["White", "Black", "Blue"]},
{name: "Dress Shirt", price: 49.95, category: "Fashion", description: "A stylish dress shirt suitable for formal occasions.", inStock: true, colors: ["White", "Blue", "Pink", "Gray"]},
{name: "Yoga Mat", price: 29.99, category: "Sports", description: "A non-slip yoga mat for comfortable workouts.", inStock: true, colors: ["Purple", "Blue", "Green"]},
{name: "Coffee Maker", price: 69.95, category: "Appliances", description: "A programmable coffee maker for your daily brew.", inStock: false, colors: ["Black", "White"]},
{name: "Digital Camera", price: 349.0, category: "Electronics", description: "A high-resolution digital camera for capturing memories.", inStock: true, colors: ["Black"]},
];
db.products.insertMany(productsData);
console.log(`${database}.${collection} has ${db.products.countDocuments()} documents.`);
const inStock = db.products.find({ inStock: true }).toArray();
fs.writeFileSync('products.txt', JSON.stringify(inStock));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment