搜尋

首頁  >  問答  >  主體

MongoDB查詢問題請教

在寫查詢的時候,感覺目前的資料結構包含一個數組,而我現在要從這個數組去匹配,然後把這個數組回傳給客戶端。
過濾出訂單中包含有我們店菜的那些訂單

{
    "_id" : "xSrtZDCqJHNbAXGPe",
    "type" : "takeaway",
    "state" : "new",
    "customer" : {
        "openId" : "oFTzvsxQNk6pYeTwTsZ-mkUGTMVM",
        "name" : "张灏哲",
        "mobile" : "13354261882",
        "campus" : "北华大学东校区",
        "building" : "第一教学楼A区",
        "room" : "301"
    },
    "items" : [ 
        {
            "_id" : "HEFFXf4SrpoSwm2ng",
            "name" : "酱香猪排饭",
            "unit" : "份",
            "price" : 10,
            "vendor" : "王记美食",
            "image" : "QjTbqCq89Gb43ER2C",
            "imageSUrl" : "/cfs/files/takeaway/QjTbqCq89Gb43ER2C/6YWx6aaZ54yq5o6S6aWt.jpg?token=eyJhdXRoVG9rZW4iOiJ6WlNQVEZiVnpRVmdSQUVhbnlPQVBDaDRfX0I4RDRjUTI4X3ZhdTdnZjJRIn0%3D&store=takeaway-s",
            "imageMUrl" : "/cfs/files/takeaway/QjTbqCq89Gb43ER2C/6YWx6aaZ54yq5o6S6aWt.jpg?token=eyJhdXRoVG9rZW4iOiJ6WlNQVEZiVnpRVmdSQUVhbnlPQVBDaDRfX0I4RDRjUTI4X3ZhdTdnZjJRIn0%3D&store=takeaway-m",
            "imageLUrl" : "/cfs/files/takeaway/QjTbqCq89Gb43ER2C/6YWx6aaZ54yq5o6S6aWt.jpg?token=eyJhdXRoVG9rZW4iOiJ6WlNQVEZiVnpRVmdSQUVhbnlPQVBDaDRfX0I4RDRjUTI4X3ZhdTdnZjJRIn0%3D&store=takeaway-l",
            "amount" : 1
        }, 
        {
            "_id" : "3WRCcJ68iPWsstqG4",
            "name" : "酱香卤肉饭",
            "unit" : "份",
            "price" : 10,
            "vendor" : "王记美食",
            "image" : "bqnnFyTM6u6J2Qnjo",
            "imageSUrl" : "/cfs/files/takeaway/bqnnFyTM6u6J2Qnjo/6YWx6aaZ5Y2k6IKJ6aWt.jpg?token=eyJhdXRoVG9rZW4iOiJ6WlNQVEZiVnpRVmdSQUVhbnlPQVBDaDRfX0I4RDRjUTI4X3ZhdTdnZjJRIn0%3D&store=takeaway-s",
            "imageMUrl" : "/cfs/files/takeaway/bqnnFyTM6u6J2Qnjo/6YWx6aaZ5Y2k6IKJ6aWt.jpg?token=eyJhdXRoVG9rZW4iOiJ6WlNQVEZiVnpRVmdSQUVhbnlPQVBDaDRfX0I4RDRjUTI4X3ZhdTdnZjJRIn0%3D&store=takeaway-m",
            "imageLUrl" : "/cfs/files/takeaway/bqnnFyTM6u6J2Qnjo/6YWx6aaZ5Y2k6IKJ6aWt.jpg?token=eyJhdXRoVG9rZW4iOiJ6WlNQVEZiVnpRVmdSQUVhbnlPQVBDaDRfX0I4RDRjUTI4X3ZhdTdnZjJRIn0%3D&store=takeaway-l",
            "amount" : 2
        }, 
        {
            "_id" : "w4BNrrM8aWoTR2fqd",
            "name" : "板烧梅肉饭",
            "unit" : "份",
            "price" : 10,
            "vendor" : "王记美食",
            "image" : "FqTTadroGpcieaERZ",
            "imageSUrl" : "/cfs/files/takeaway/FqTTadroGpcieaERZ/5p2_54On5qKF6IKJ6aWt.jpg?token=eyJhdXRoVG9rZW4iOiJ6WlNQVEZiVnpRVmdSQUVhbnlPQVBDaDRfX0I4RDRjUTI4X3ZhdTdnZjJRIn0%3D&store=takeaway-s",
            "imageMUrl" : "/cfs/files/takeaway/FqTTadroGpcieaERZ/5p2_54On5qKF6IKJ6aWt.jpg?token=eyJhdXRoVG9rZW4iOiJ6WlNQVEZiVnpRVmdSQUVhbnlPQVBDaDRfX0I4RDRjUTI4X3ZhdTdnZjJRIn0%3D&store=takeaway-m",
            "imageLUrl" : "/cfs/files/takeaway/FqTTadroGpcieaERZ/5p2_54On5qKF6IKJ6aWt.jpg?token=eyJhdXRoVG9rZW4iOiJ6WlNQVEZiVnpRVmdSQUVhbnlPQVBDaDRfX0I4RDRjUTI4X3ZhdTdnZjJRIn0%3D&store=takeaway-l",
            "amount" : 1
        }
    ],
    "orderNo" : 3,
    "orderTime" : "2016-03-23 04:10:45"
}

我要從items這個數組中去匹配vendor,將匹配成功的vendor返回給對呀的商戶,比如我匹配`vendor === '王記美食',匹配成功的話,則匹配成功的話,則匹配。將這個order回傳給商家的客戶端,商家可以看到他們賣了什麼。

求大神們給個思路,sql用的不精。

我是在meteor中publish的

習慣沉默習慣沉默2803 天前632

全部回覆(1)我來回復

  • 某草草

    某草草2017-05-02 09:19:57

    雷雷

    回覆
    0
  • 取消回覆