Пн goose `let` не поддерживается - PullRequest
1 голос
/ 20 июня 2020

Фон: Я создаю приложение MERN Stack Travel Application, и я работал над созданием запроса для получения одного объекта комнаты из каждого типа комнаты из коллекции Room. Мне удалось это сделать, и вы можете увидеть здесь .

Проблема: Проблема, с которой я столкнулся, заключается в том, что я работал на mongoplayground и когда я пытаюсь интегрировать запрос, я получаю сообщение об ошибке от mon goose с надписью let not supported. Кажется, я не понимаю, что я сделал не так. Любая помощь будет принята с благодарностью

Stack Trace:

enter image description here

Интеграция с NodeJS :

const express = require("express");
const router = express.Router();
const { ObjectId } = require("mongodb");
const Hotel = require("../models/HotelManagment/Hotel");

router.post("/uniquerooms", auth, async (req, res) => {
  try {
    let id = ObjectId(req.user.id);
    const uniquerooms = await Hotel.aggregate(
      [
        {
          $match: {
            hotelRep: id,
          },
        },
        {
          $lookup: {
            from: "hotelReps",
            as: "HotelRep",
            let: {
              hotelRep: "$hotelRep",
            },
            pipeline: [
              {
                $match: {
                  $expr: {
                    $and: [
                      {
                        $eq: ["$_id", "$$hotelRep"],
                      },
                    ],
                  },
                },
              },
            ],
          },
        },
        {
          $lookup: {
            from: "rooms",
            as: "Room",
            let: {
              id: "$_id",
            },
            pipeline: [
              {
                $facet: {
                  Economy: [
                    {
                      $match: {
                        $expr: {
                          $and: [
                            {
                              $eq: ["$type", "Economy"],
                            },
                            {
                              $eq: ["$hotelId", "$$id"],
                            },
                          ],
                        },
                      },
                    },
                    {
                      $limit: 1,
                    },
                  ],
                  Delexue: [
                    {
                      $match: {
                        $expr: {
                          $and: [
                            {
                              $eq: ["$type", "Delexue"],
                            },
                            {
                              $eq: ["$hotelId", "$$id"],
                            },
                          ],
                        },
                      },
                    },
                    {
                      $limit: 1,
                    },
                  ],
                  Luxury: [
                    {
                      $match: {
                        $expr: {
                          $and: [
                            {
                              $eq: ["$type", "Luxury"],
                            },
                            {
                              $eq: ["$hotelId", "$$id"],
                            },
                          ],
                        },
                      },
                    },
                    {
                      $limit: 1,
                    },
                  ],
                },
              },
              {
                $project: {
                  activity: {
                    $setUnion: ["$Economy", "$Luxury", "$Delexue"],
                  },
                },
              },
              {
                $unwind: "$activity",
              },
              {
                $replaceRoot: {
                  newRoot: "$activity",
                },
              },
            ],
          },
        },
        {
          $unwind: "$Room",
        },
        {
          $replaceRoot: {
            newRoot: "$Room",
          },
        },
      ],
      (err, response) => {
        if (err) res.status(400).json({ err });
        console.log(uniquerooms);
        res.json(uniquerooms);
      }
    );
  } catch (err) {
    console.error(err.message);
    res.status(500).send("Server Error");
  }
});
...