Search⌘ K
AI Features

Write Query: Insert a Record

To insert a new order into the MongoDB orders collection, a document must be created with specific fields: a unique `_id`, `customerId`, an array of `items`, `total`, `status`, and `orderDate`. For example, a new order can be added for customer ID "827deda15a36ab11ff88ca3d" with items "Smartphone" and "Wireless Earbuds," totaling 1750, and a status of "Pending." The expected output confirms the operation's success with an acknowledgment and a randomly generated `insertedId`.

We'll cover the following...

Question

Given the following sample documents from the orders collection:

[
  {
    "_id": "3a758b14e7e292cf190b1ac5",
    "customerId": "ee3c04494293e51a48af88d1",
    "items": [
      "External Hard Drive",
      "USB Hub"
    ],
    "total": 1922,
    "status": "Processing",
    "orderDate": ISODate("2024-07-05T00:00:00Z&
...