aldinokemal

MongoDB - Insert

Mar 27th, 2022 (edited)
264
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Insert document customers
  2. db.customers.insertOne({
  3.     _id: "ak",
  4.     name: "Aldino Kemal"
  5. });
  6.  
  7. // Insert document products
  8. db.products.insertMany([
  9.     {
  10.         _id: 1,
  11.         name: "Indomie Ayam Bawang",
  12.         price: new NumberLong('2000')
  13.     },
  14.     {
  15.         _id: 2,
  16.         name: "Mie Sedap",
  17.         price: new NumberLong('2000')
  18.     }
  19. ]);
  20.  
  21. // Insert document orders
  22. db.orders.insertOne({
  23.     _id: new ObjectId(),
  24.     total: new NumberLong(8000),
  25.     items: [
  26.         {
  27.             product_id: 1,
  28.             price: new NumberLong('2000'),
  29.             quantity: new NumberInt(2)
  30.         },
  31.         {
  32.             product_id: 2,
  33.             price: new NumberLong('2000'),
  34.             quantity: new NumberInt(2)
  35.         }
  36.     ]
  37. })
Add Comment
Please, Sign In to add comment