91超碰碰碰碰久久久久久综合_超碰av人澡人澡人澡人澡人掠_国产黄大片在线观看画质优化_txt小说免费全本

溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

MongoDB之數據查詢(嵌套集合)

發布時間:2020-08-11 11:01:11 來源:ITPUB博客 閱讀:160 作者:stonebox1122 欄目:關系型數據庫
MongoDB數據庫里面每一個集合數據可以繼續保存其他的集合數據,例如有些人員保存家庭信息。

范例:增加數據
db.emp.insert({"name":"林A","sex":"男","age":22,"sal":8000,"loc":"北京","course":["語文","數學","英語","音樂","政治"],"parents":[{"name":"林A父親","age":50,"job":"農民"},{"name":"林A母親","age":49,"job":"工人"}]});
db.emp.insert({"name":"林B","sex":"男","age":30,"sal":8000,"loc":"北京","course":["語文","數學"],"parents":[{"name":"林B父親","age":55,"job":"工人"},{"name":"林B母親","age":52,"job":"農民"}]});
db.emp.insert({"name":"林C","sex":"男","age":35,"sal":8000,"loc":"北京","course":["語文","數學","英語"],"parents":[{"name":"林C父親","age":60,"job":"工人"},{"name":"林C母親","age":59,"job":"職員"}]});
db.emp.insert({"name":"林D","sex":"男","age":28,"sal":8000,"loc":"北京","course":["語文","數學","政治"],"parents":[{"name":"林D父親","age":58,"job":"局長"},{"name":"林D母親","age":54,"job":"處長"}]});
db.emp.insert({"name":"林E","sex":"男","age":40,"sal":8000,"loc":"北京","course":["語文","政治"],"parents":[{"name":"林E父親","age":70,"job":"工人"},{"name":"林E母親","age":68,"job":"局長"}]});

此時的內容是嵌套的集合,而這種集合的數據的判斷只能通過“$elemMatch”來完成。

范例:查詢出父母之中有局長的信息
> db.emp.find({"$and":[{"age":{"$gte":30}},{"parents":{"$elemMatch":{"job":"局長"}}}]}).pretty();
{
        "_id" : ObjectId("599148bf0184ff511bf02b95"),
        "name" : "林E",
        "sex" : "男",
        "age" : 40,
        "sal" : 8000,
        "loc" : "北京",
        "course" : [
                "語文",
                "政治"
        ],
        "parents" : [
                {
                        "name" : "林E父親",
                        "age" : 70,
                        "job" : "工人"
                },
                {
                        "name" : "林E母親",
                        "age" : 68,
                        "job" : "局長"
                }
        ]
}
由于這種查詢的時候條件比較麻煩,所以如果可能,盡量別搞這么復雜。
向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

永济市| 宁武县| 浙江省| 惠安县| 湘阴县| 万安县| 舒兰市| 杭锦旗| 尼木县| 文登市| 宁陕县| 瑞安市| 浦县| 堆龙德庆县| 浦江县| 怀来县| 荆州市| 呼图壁县| 桦南县| 蒙阴县| 萝北县| 济宁市| 巧家县| 万源市| 潍坊市| 泰兴市| 河曲县| 张掖市| 广汉市| 河南省| 洞头县| 西和县| 泗水县| 英吉沙县| 天柱县| 吴桥县| 会泽县| 巨鹿县| 德昌县| 皮山县| 枞阳县|