0

Mongo データベースには、コレクション ストアがあります。ネストされたクエリを実行したいのですが、実行できないようです。

db.store.find()

これにより、すべてのコレクションが返されます。

現在、各店舗にアイテムが

すべてのアイテムを入手するにはどうすればよいですか。1店舗の全商品だけでなく、各店舗の全商品。

db.store.find(item:{i don't want a query i want them all})

問題は、アイテムのクエリを実行したくないことです。すべてのアイテムが必要なだけです。入力していただきありがとうございます。

うーん編集?私が試したことは

db.store.find() と入力すると

        "_id" : ObjectId("52695741d6b0a8701a0000ad"),
        "name" : "Non Dui Nec LLP",
        "code" : "YFY37YEQ0VZ",
        "url" : "www.txvhmjkcyirjmb.com",
        "facebook_link" : "http://facebook.com/qhhonsm",
        "twitter_link" : "http://twitter.com/sqwmpbcqx",
        "items" : [
                {
                        "user_id" : 6,
                        "code" : "HKS29TGT1QE",
                        "name" : "Lorem Donec LLP",
                        "description" : "adipiscing elit. Etiam laoreet, libero
et tristique pellentesque, tellus sem mollis dui, in sodales elit erat vitae ris
us. Duis a mi fringilla mi lacinia mattis. Integer eu lacus. Quisque imperdiet,
erat nonummy ultricies ornare, elit elit fermentum risus, at fringilla purus mau
ris a nunc. In at pede. Cras",
                        "featured" : "false",
                        "price" : 22278,
                        "quantity" : 2,
                        "views" : 229917,
                        "category_id" : 6,
                        "brand" : "Metus Sit Amet Inc.",
                        "rating" : 2,
                        "sale" : "true",
                        "sale_price" : 49437,
                        "online" : "true",
                        "store" : "true"
                },
                {
                        "user_id" : 6,
                        "code" : "UXS08MIR6ZV",
                        "name" : "Quisque Inc.",
                        "description" : "amet nulla. Donec non justo. Proin non
massa non ante bibendum ullamcorper. Duis cursus, diam at pretium aliquet,",
                        "featured" : "false",
                        "price" : 42511,
                        "quantity" : 8,
                        "views" : 372823,
                        "category_id" : 3,
                        "brand" : "Amet Metus PC",
                        "rating" : 5,
                        "sale" : "true",
                        "sale_price" : 31672,
                        "online" : "true",
                        "store" : "false"
                },
                {
                        "user_id" : 2,
                        "code" : "DBK19WNP4MK",
                        "name" : "Mauris Molestie Pharetra PC",
                        "description" : "volutpat. Nulla facilisis. Suspendisse
commodo tincidunt nibh. Phasellus nulla. Integer vulputate, risus a ultricies ad
ipiscing, enim mi tempor lorem, eget mollis lectus pede et risus. Quisque libero
 lacus, varius et, euismod et, commodo at, libero. Morbi accumsan laoreet ipsum.
 Curabitur consequat, lectus sit amet luctus vulputate, nisi sem semper",
                        "featured" : "true",
                        "price" : 39186,
                        "quantity" : 7,
                        "views" : 343691,
                        "category_id" : 5,
                        "brand" : "Malesuada LLP",
                        "rating" : 5,
                        "sale" : "false",
                        "sale_price" : 2929,
                        "online" : "true",
                        "store" : "true"
                },
                {
                        "user_id" : 2,
                        "code" : "VGT01QNU1AE",
                        "name" : "Amet Ornare Lectus Associates",
                        "description" : "ipsum. Phasellus vitae mauris sit amet
lorem semper auctor. Mauris vel turpis. Aliquam adipiscing lobortis risus. In mi
 pede, nonummy ut, molestie in, tempus eu, ligula. Aenean euismod mauris eu elit
. Nulla facilisi. Sed neque. Sed eget lacus. Mauris non dui nec urna suscipit no
nummy.",
                        "featured" : "true",
                        "price" : 25581,
                        "quantity" : 9,
                        "views" : 237448,
                        "category_id" : 1,
                        "brand" : "Risus Nulla Eget LLP",
                        "rating" : 5,
                        "sale" : "false",
                        "sale_price" : 25998,
                        "online" : "true",
                        "store" : "false"
                },
                {
                        "user_id" : 8,
                        "code" : "XYT91KLX5LC",
                        "name" : "Nunc Nulla Consulting",
                        "description" : "posuere vulputate, lacus. Cras interdum
. Nunc sollicitudin commodo ipsum. Suspendisse non leo. Vivamus nibh dolor, nonu
mmy ac, feugiat non, lobortis quis, pede.",
                        "featured" : "true",
                        "price" : 55233,
                        "quantity" : 8,
                        "views" : 102238,
                        "category_id" : 4,
                        "brand" : "Diam Eu Dolor Company",
                        "rating" : 4,
                        "sale" : "true",
                        "sale_price" : 28494,
                        "online" : "false",
                        "store" : "true"
                },
                {
                        "user_id" : 3,
                        "code" : "QGD53OAH0LJ",
                        "name" : "Tempus Eu Incorporated",
                        "description" : "non enim. Mauris quis turpis vitae puru
s gravida sagittis. Duis gravida. Praesent eu nulla at sem molestie sodales. Mau
ris blandit enim consequat purus. Maecenas libero est, congue a, aliquet vel, vu
lputate eu, odio. Phasellus at augue id ante dictum cursus. Nunc mauris elit,",
                        "featured" : "false",
                        "price" : 36669,
                        "quantity" : 10,
                        "views" : 129981,
                        "category_id" : 6,
                        "brand" : "Felis Purus Ac Company",
                        "rating" : 2,
                        "sale" : "false",
                        "sale_price" : 28753,
                        "online" : "true",
                        "store" : "true"
                },
                {
                        "user_id" : 9,
                        "code" : "NCI04XCU9OE",
                        "name" : "Ipsum Suspendisse Ltd",
                        "description" : "luctus vulputate, nisi sem semper erat,
 in consectetuer ipsum nunc id enim. Curabitur massa. Vestibulum accumsan neque
et nunc. Quisque ornare tortor",
                        "featured" : "true",
                        "price" : 67414,
                        "quantity" : 9,
                        "views" : 402667,
                        "category_id" : 4,
                        "brand" : "Quisque Porttitor PC",
                        "rating" : 5,
                        "sale" : "false",
                        "sale_price" : 10481,
                        "online" : "true",
                        "store" : "false"
                }
        ]
}
{
        "_id" : ObjectId("52695741d6b0a8701a0000ae"),
        "name" : "Urna Institute",
        "code" : "YRH20JFJ0PW",
        "url" : "www.cfejurcgjtdvjf.com",
        "facebook_link" : "http://facebook.com/yzcbixz",
        "twitter_link" : "http://twitter.com/aehbnnloc",
        "items" : [
                {
                        "user_id" : 1,
                        "code" : "VEI96FAL1OQ",
                        "name" : "Ornare Facilisis Eget Corp.",
                        "description" : "arcu. Vestibulum ante ipsum primis in f
aucibus orci luctus et ultrices posuere cubilia Curae; Phasellus ornare. Fusce m
ollis. Duis sit amet diam eu dolor egestas rhoncus. Proin nisl sem, consequat ne
c, mollis vitae, posuere at, velit. Cras lorem lorem, luctus ut, pellentesque eg
et, dictum placerat, augue. Sed molestie. Sed id",
                        "featured" : "true",
                        "price" : 67040,
                        "quantity" : 1,
                        "views" : 231128,
                        "category_id" : 2,
                        "brand" : "Sed Nec Consulting",
                        "rating" : 3,
                        "sale" : "false",
                        "sale_price" : 7198,
                        "online" : "false",
                        "store" : "true"
                },
                {
                        "user_id" : 3,
                        "code" : "JKT20ZIN1WE",
                        "name" : "Nulla Tempor Augue Incorporated",
                        "description" : "eleifend. Cras sed leo. Cras vehicula a
liquet libero. Integer in magna. Phasellus dolor elit, pellentesque a, facilisis
 non, bibendum sed, est. Nunc laoreet lectus quis massa. Mauris vestibulum, nequ
e sed dictum eleifend, nunc risus varius orci, in consequat enim diam vel arcu.
Curabitur ut",
                        "featured" : "true",
                        "price" : 51700,
                        "quantity" : 6,
                        "views" : 195004,
                        "category_id" : 5,
                        "brand" : "Mauris Institute",
                        "rating" : 4,
                        "sale" : "false",
                        "sale_price" : 44753,
                        "online" : "false",
                        "store" : "true"
                },
                {
                        "user_id" : 2,
                        "code" : "HNJ55IWD4TH",
                        "name" : "Ac Feugiat Limited",
                        "description" : "tristique ac, eleifend vitae, erat. Viv
amus nisi. Mauris nulla. Integer urna. Vivamus molestie dapibus ligula. Aliquam
erat",
                        "featured" : "false",
                        "price" : 70134,
                        "quantity" : 9,
                        "views" : 440143,
                        "category_id" : 4,
                        "brand" : "Eu Incorporated",
                        "rating" : 4,
                        "sale" : "false",
                        "sale_price" : 8213,
                        "online" : "false",
                        "store" : "false"
                },
                {
                        "user_id" : 3,
                        "code" : "OUZ13HAN7UV",
                        "name" : "At LLC",
                        "description" : "nonummy ipsum non arcu. Vivamus sit ame
t risus. Donec egestas. Aliquam nec enim. Nunc ut erat. Sed nunc est, mollis non
, cursus",
                        "featured" : "true",
                        "price" : 1468,
                        "quantity" : 10,
                        "views" : 371808,
                        "category_id" : 4,
                        "brand" : "Venenatis Associates",
                        "rating" : 4,
                        "sale" : "false",
                        "sale_price" : 48312,
                        "online" : "true",
                        "store" : "false"
                },
                {
                        "user_id" : 3,
                        "code" : "BAK14SFY4ZT",
                        "name" : "Consectetuer Euismod Corp.",
                        "description" : "Etiam ligula tortor, dictum eu, placera
t eget, venenatis a, magna. Lorem ipsum dolor sit amet, consectetuer adipiscing
elit. Etiam laoreet, libero et tristique pellentesque, tellus sem mollis dui, in
 sodales elit erat vitae risus. Duis a mi fringilla mi lacinia mattis. Integer e
u lacus. Quisque imperdiet, erat nonummy",
                        "featured" : "true",
                        "price" : 95615,
                        "quantity" : 8,
                        "views" : 365175,
                        "category_id" : 3,
                        "brand" : "Donec Nibh Enim Incorporated",
                        "rating" : 3,
                        "sale" : "true",
                        "sale_price" : 12858,
                        "online" : "false",
                        "store" : "false"
                },
                {
                        "user_id" : 6,
                        "code" : "FNF49YPX4PQ",
                        "name" : "Morbi Institute",
                        "description" : "sit amet risus. Donec egestas. Aliquam
nec enim. Nunc ut erat. Sed nunc est, mollis non, cursus non, egestas a, dui. Cr
as pellentesque. Sed dictum. Proin eget odio. Aliquam vulputate ullamcorper magn
a. Sed eu eros. Nam consequat dolor vitae dolor. Donec fringilla. Donec feugiat
metus sit amet ante. Vivamus non",
                        "featured" : "true",
                        "price" : 94975,
                        "quantity" : 9,
                        "views" : 243181,
                        "category_id" : 3,
                        "brand" : "Elementum Purus Foundation",
                        "rating" : 1,
                        "sale" : "true",
                        "sale_price" : 49337,
                        "online" : "true",
                        "store" : "true"
                },
                {
                        "user_id" : 5,
                        "code" : "CAQ49OCW9SN",
                        "name" : "Sit Incorporated",
                        "description" : "Nunc ut erat. Sed nunc est, mollis non,
 cursus non, egestas",
                        "featured" : "false",
                        "price" : 98576,
                        "quantity" : 10,
                        "views" : 265153,
                        "category_id" : 3,
                        "brand" : "Fringilla Euismod Corporation",
                        "rating" : 5,
                        "sale" : "false",
                        "sale_price" : 7037,
                        "online" : "false",
                        "store" : "false"
                }
        ]
}

そして、すべての店が持っているすべてのアイテムを手に入れたいです。どのように説明すればよいかわかりませんが、すべての店舗ですべての商品を手に入れようとしています。それでもわかりにくい場合はお知らせください。もっと例を投稿できます

4

1 に答える 1

2

次のような意味ですか。

db.store.aggregate([
    {$unwind: "$items"},
    {$project: {
        "user_id" : "$items.user_id",
        "code" : "$items.code",
        "name" : "$items.name",
        "description" : "$items.description",
        "featured" : "$items.featured",
        "quantity" : "$items.quantity",
        "views" : "$items.views",
        "category_id" : "$items.category_id",
        "brand" : "$items.brand",
        "rating" : "$items.rating",
        "sale" : "$items.sale",
        "sale_price" : "$items.sale_price",
        "online" : "$items.online",
        "store" : "$items.store",
        "_id": 0
    }}
])

{$unwind: "$items"}items配列内の各サブドキュメントに対して個別のドキュメントを作成します。次のような配列が得られます。

[

    {
        "_id" : ObjectId("52693d98e7792c81a7f4e5ad"),
        "items" : {
            "user_id" : 6,
            "code" : "HKS29TGT1QE",
            ...
        }

            ... //Other fields

    },
    {
        "_id" : ObjectId("52693d98e7792c81a7f4e5ad"),
        "items" : {
            "user_id" : 6,
            "code" : "UXS08MIR6ZV",
            "name" : "Quisque Inc.",
            ...
        }
            ... //Other fields
    }
]

は親ドキュメントの です"_id"。サブドキュメントから興味深いフィールドを削除および抽出するために_id使用できます。{$project: {...}}_iditems

編集

おそらくproject 、パイプラインの最初に simple を使用して、下流に向かうドキュメントのサイズを減らすことができます。

db.store.aggregate([
    {$project: {"items": 1}},
    {$unwind: "$items"},
    {$project: {
        "user_id" : "$items.user_id",
        ...
    }}
]}
于 2013-10-24T15:26:11.900 に答える