Holen Sie sich geschachtelte Felder mit MongoDB shell

Habe ich "Benutzer" - Kollektion mit "Watchlisten" - Feld, die haben viele innere Felder zu, man ist "arrangeable_values" (das zweite Feld innerhalb von "Watchlisten").

Ich muss für jeden Benutzer in "Benutzer" - Kollektion, die jeweils "arrangeable_values" innerhalb von "Watchlisten".

Wie kann ich das mit mongodb shell ?

Hier ist ein Beispiel für Daten Modell :

> db.users.findOne({'nickname': 'superj'})
{
    "_id" : ObjectId("4f6c42f6018a590001000001"),
    "nickname" : "superj",
    "provider" : "github",
    "user_hash" : null,
    "watchlists" : [
        {
            "_id" : ObjectId("4f6c42f7018a590001000002"),
            "arrangeable_values" : {
                "description" : "My introduction presentation to node.js along with sample code at various stages of building a simple RESTful web service with journey, cradle, winston, optimist, and http-console.",
                "tag" : "",
                "html_url" : "https://github.com/indexzero/nodejs-intro"
            },
            "avatar_url" : "https://secure.gravatar.com/avatar/d43e8ea63b61e7669ded5b9d3c2e980f?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png",
            "created_at" : ISODate("2011-02-01T10:20:29Z"),
            "description" : "My introduction presentation to node.js along with sample code at various stages of building a simple RESTful web service with journey, cradle, winston, optimist, and http-console.",
            "fork_" : false,
            "forks" : 13,
            "html_url" : "https://github.com/indexzero/nodejs-intro",
            "pushed_at" : ISODate("2011-09-12T17:54:58Z"),
            "searchable_values" : [
                "description:my",
                "description:introduction",
                "description:presentation",
                "html_url:indexzero",
                "html_url:nodejs",
                "html_url:intro"
            ],
            "tags_array" : [ ],
            "watchers" : 75
        },
    {
        "_id" : ObjectId("4f6c42f7018a590001000003"),
        "arrangeable_values" : {
            "description" : "A Backbone alternative idea",
            "tag" : "",
            "html_url" : "https://github.com/maccman/spine.todos"
        },
        "avatar_url" : "https://secure.gravatar.com/avatar/baf018e2cc4616e4776d323215c7136c?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png",
        "created_at" : ISODate("2011-03-18T11:03:42Z"),
        "description" : "A Backbone alternative idea",
        "fork_" : false,
        "forks" : 31,
        "html_url" : "https://github.com/maccman/spine.todos",
        "pushed_at" : ISODate("2011-11-20T22:59:45Z"),
        "searchable_values" : [
            "description:a",
            "description:backbone",
            "description:alternative",
            "description:idea",
            "html_url:https",
            "html_url:github",
            "html_url:com",
            "html_url:maccman",
            "html_url:spine",
            "html_url:todos"
        ],
        "tags_array" : [ ],
        "watchers" : 139
    }
    ]
}
InformationsquelleAutor BBJ3 | 2012-04-07
Schreibe einen Kommentar