Mongoose - 在数组中搜索数组

时间:2018-02-20 20:33:52

标签: node.js mongoose

我有以下模型

"reserved_days": [
    {
        "pk": 3543,
        "date": "2018-07-14",
        "price": 3213.0,
        "payment_type": "Безналичный расчет",
        "payment_date": "2017-12-28",
        "room": {
            "room_id": "7",
            "name": "Стандарт"
        }
    },
    {
        "pk": 3544,
        "date": "2018-07-15",
        "price": 3213.0,
        "payment_type": "Безналичный расчет",
        "payment_date": "2017-12-28",
        "room": {
            "room_id": "7",
            "name": "Стандарт"
        }
    }]

我预订了一系列reserved_days。我需要在数据库中比较这个预订和预订,并找到至少有一个reserved_days日期或者reserved_days room.room_id与数组中包含的相同的预约。数组不能完全相等,我只需找到重复的日期。

现在我尝试以下

-- since table_in is a temporary table, we need to copy it first.
CREATE TEMPORARY TABLE table_in2 SELECT * FROM table_in;

CREATE TEMPORARY TABLE table_out SELECT table_out_alias.*
                             FROM (
                                    SELECT
                                      user_id AS user_id,
                                      value   AS value,
                                      ''      AS specs
                                    FROM table_1
                                    WHERE user_id IN (SELECT user_id
                                                      FROM table_in)
                                          AND (field_id = 10 AND value = 'Multi')
                                    UNION ALL
                                    SELECT
                                      user_id AS user_id,
                                      ''      AS value,
                                      specs   AS specs
                                    FROM table_2
                                    WHERE status != 'Busy' AND user_id IN (SELECT user_id
                                                                           FROM table_in2)
                                  ) AS table_out_alias

但它不起作用。

测试请求reservation.reserved_days对象看起来如下

public function store(Request $request){
      $Advert = new PropertyAdvert();

      $Advert::create(
        [
          "photo"       => $request->photo,
          "address"     => $request->address,
          "county"      => $request->county,
          "town"        => $request->town,
          "type"        => $request->type,
          "rent"        => $request->rent,
          "date"        => $request->date,
          "bedrooms"    => $request->bedrooms,
          "bathrooms"   => $request->bathrooms,
          "furnished"   => $request->furnished,
          "description" => $request->description
        ]
      );

      return "Success. Your adveret has been published";
    }

有可能吗?

0 个答案:

没有答案