0

これは私のドキュメンテーション形式です

{
    "_id" : ObjectId("5af56909b8be3925cf199924"),
    "pid" : "9354496457",
    "vid" : NumberLong("34756636617"),
    "title" : "Ascolour Barnard Stripe Tank Tee-(5032)",
    "handle" : "ascolour-barnard-stripe-tank-tee-5032",
    "image" : "https://cdn.shopify.com/s/files/1/1919/3401/products/5032_barnard_stripe_tank_natural_black_5.jpg?v=1493879380",
    "color" : "XL",
    "size" : "NATURAL/BLACK",
    "width" : null,
    "activity" : "",
    "brand" : "Ascolour",
    "style" : "",
    "feature" : "",
    "type" : "Adult Singlets",
    "price" : 1100,
    "compare_at_price" : 1100,
    "qty" : 1,
    "sku" : "5032",
    "visible" : 1
}
{
    "_id" : ObjectId("5af56909b8be3925cf199925"),
    "pid" : "9354496457",
    "vid" : NumberLong("34756636681"),
    "title" : "Ascolour Barnard Stripe Tank Tee-(5032)",
    "handle" : "ascolour-barnard-stripe-tank-tee-5032",
    "image" : "https://cdn.shopify.com/s/files/1/1919/3401/products/5032_barnard_stripe_tank_natural_black_5.jpg?v=1493879380",
    "color" : "2XL",
    "size" : "NATURAL/BLACK",
    "width" : null,
    "activity" : "",
    "brand" : "Ascolour",
    "style" : "",
    "feature" : "",
    "type" : "Adult Singlets",
    "price" : 1100,
    "compare_at_price" : 1100,
    "qty" : 1,
    "sku" : "5032",
    "visible" : 1
}

ここでは、 「type」=>「adult Singlet」を個別の「pid」で検索し、ドキュメント内のすべての列を投影します

だから私はクエリを書きます:

$cursor = $songs->aggregate([
                ['$project' => ['_id' => 1, 'title' => 1, 'size' => 1]],
                ['$match' =>
                    ['$and' => [
                            ['$or' => [
                                    ['title' => $regex],
                                    ['size' => $regex],
                                    ['color' => $regex],
                                    ['brand' => $regex],
                                    ['activity' => $regex],
                                    ['style' => $regex],
                                    ['type' => $regex],
                                    ['feature' => $regex],
                                    ['width' => $regex],
                            ]
                        ],
                            ['visible' => ['$eq' => 1]],
                            ['qty' => ['$gt' => 0]],
                    ]
                ]
            ],
                ['$group' => ["_id" => '$pid']],
                ['$limit' => 10]
        ]);

しかし、何も表示されず、この行を削除すると

['$project' => ['_id' => 1, 'タイトル' => 1, 'サイズ' => 1]]

次に、すべての異なるpidを表示します。しかし、私はすべての列wrtの個別のpidを表示する必要があります

前もって感謝します :)

4

1 に答える 1