Các lượt nộp
    Danh sách bài
    Trang chủ
    Báo lỗi
    solution
    Đăng nhập
    Đăng nhập

    Đề bài: Áp suất cao trong thời tiết

    Lọc các bản ghi thời tiết có áp suất cao: pressure.value > 1020. Lưu ý: trong dữ liệu mẫu, giá trị 9999.9 nghĩa là không đo được (giá trị thiếu), nên chỉ xét các bản ghi có 1020 < pressure.value < 9999.

    Sau đó:

    • Sắp xếp theo pressure.value giảm dần; nếu bằng nhau thì theo ts tăng dần, rồi st tăng dần.
    • Lấy 10 bản ghi đầu tiên.
    • $project chỉ hiển thị st, pressure.value, ts (không hiển thị _id).

    Pipeline: match+match + match+sort + limit+limit + limit+project. Không cần lệnh use.

    • Định dạng đầu vào:

      Collection data (dữ liệu mẫu sample_weatherdata.data) đã được nạp sẵn.

    • Định dạng đầu ra:

      In ra kết quả của câu lệnh aggregate (chỉ một câu truy vấn này được in): mảng 10 document theo định dạng mongosh. Thứ tự các trường trong mỗi document theo thứ tự trong dữ liệu gốc (st, ts, pressure), ví dụ một phần tử:

        {
          st: 'x+62200-008400',
          ts: ISODate('1984-03-12T06:00:00.000Z'),
          pressure: { value: 1059.4 }
        },
      

    Ví dụ:

    Đầu vào:

    sample_weatherdata.data

    Đầu ra:

    [
      {
        st: 'x+62200-008400',
        ts: ISODate('1984-03-12T06:00:00.000Z'),
        pressure: { value: 1059.4 }
      },
      {
        st: 'x+48000-005200',
        ts: ISODate('1984-03-07T12:00:00.000Z'),
        pressure: { value: 1054.7 }
      },
      {
        st: 'x+61300-002900',
        ts: ISODate('1984-03-07T18:00:00.000Z'),
        pressure: { value: 1053.4 }
      },
      {
        st: 'x+49800-004900',
        ts: ISODate('1984-03-07T12:00:00.000Z'),
        pressure: { value: 1052.3 }
      },
      {
        st: 'x+58300-004400',
        ts: ISODate('1984-03-08T12:00:00.000Z'),
        pressure: { value: 1050.6 }
      },
      {
        st: 'x+38700+134300',
        ts: ISODate('1984-03-13T00:00:00.000Z'),
        pressure: { value: 1050.3 }
      },
      {
        st: 'x+55100+006100',
        ts: ISODate('1984-03-09T18:00:00.000Z'),
        pressure: { value: 1049.8 }
      },
      {
        st: 'x+66500+010200',
        ts: ISODate('1984-03-12T01:00:00.000Z'),
        pressure: { value: 1049.2 }
      },
      {
        st: 'x+66500+010200',
        ts: ISODate('1984-03-12T09:00:00.000Z'),
        pressure: { value: 1049.1 }
      },
      {
        st: 'x+63300+020200',
        ts: ISODate('1984-03-12T12:00:00.000Z'),
        pressure: { value: 1048.4 }
      }
    ]

    Chủ đề

    🗄️ Cơ sở dữ liệuMongodbAggregationTất cả môn học

    Đang tải editor...