2017-10-28 74 views
0

TL;博士分析查詢由子/點符號

能ParseCloud/MongoDB的過濾器由Pointer<class>.filed?通過 Pointer<class>.Pointer<class>?是否存在該領域的數據?

長的問題:

Round是將自動播放時,時間會來的對象。

Payment指示用戶付款的對象。當支付正在使用時,我們將其設置爲round

Player哪些鏈接在線UserPayment

我需要查詢球員爲幾個條件:

  1. Player

    • 在線
    • 具有有效(不roundvalid到 '有效')payment
  2. Player

    • user等於特定用戶
    • 等於沒有payment
  3. Player

    • user等於特定用戶
    • 具有有效(不roundvalid等於 '有效')支付

而且我做了一切,除了驗證PaymentPlayer查詢工作。

這裏是條件從列表中。

var query = new Parse.Query(keys.Player); 
query.skip(0); 
query.limit(oneRoundMaxPlayers); 
query.greaterThanOrEqualTo(keys.last_online_date, lastAllowedOnline); 

// looks like no filter applied here 
query.doesNotExist("payment.round"); 

query.exists(keys.payment); 

// This line will make query return 0 elements 
// query.equalTo("payment.valid", "valid"); 

query.include(keys.user); 
query.include(keys.payment); 

這裏是2或3

var queryPaymentExists = new Parse.Query(keys.Player); 
queryPaymentExists.skip(0); 
queryPaymentExists.limit(1); 
queryPaymentExists.exists(keys.payment); 

//This line not filtering 
queryPaymentExists.doesNotExist(keys.payment + "." + keys.round); 

queryPaymentExists.equalTo(keys.user, user); 

// This line makes query always return 0 elements 
// queryPaymentExists.equalTo(keys.payment + "." + keys.valid, keys.payment_valid); 

var queryPaymentDoesNotExist = new Parse.Query(keys.Player); 
queryPaymentDoesNotExist.skip(0); 
queryPaymentDoesNotExist.limit(1); 
queryPaymentDoesNotExist.doesNotExist(keys.payment); 
queryPaymentDoesNotExist.equalTo(keys.user, user); 

var compoundQuery = Parse.Query.or(queryPaymentExists, queryPaymentDoesNotExist); 
compoundQuery.include(keys.user); 
compoundQuery.include(keys.payment); 
compoundQuery.include(keys.payment + "." + keys.round); 

我從蒙戈檢查日誌和他們看起來以下

verbose: REQUEST for [GET] /classes/Player: { 
    "include": "user,payment,payment.round", 
    "where": { 
    "$or": [ 
     { 
     "payment": { 
      "$exists": true 
     }, 
     "payment.round": { 
      "$exists": false 
     }, 
     "user": { 
      "__type": "Pointer", 
      "className": "_User", 
      "objectId": "ASPKs6UVwb" 
     } 
     }, 
     { 
     "payment": { 
      "$exists": false 
     }, 
     "user": { 
      "__type": "Pointer", 
      "className": "_User", 
      "objectId": "ASPKs6UVwb" 
     } 
     } 
    ] 
    } 
} 

這是響應:

verbose: RESPONSE from [GET] /classes/Player: { 
    "response": { 
    "results": [ 
     { 
     "objectId": "VHU9uwmLA7", 
     "last_online_date": { 
      "__type": "Date", 
      "iso": "2017-10-28T15:15:23.547Z" 
     }, 
     "user": { 
      "objectId": "ASPKs6UVwb", 
      "username": "cn92Ekv5WPJcuHjkmTajmZMDW", 

      }, 
      "createdAt": "2017-10-22T11:43:16.804Z", 
      "updatedAt": "2017-10-25T09:23:20.035Z", 


      "ACL": { 
      "*": { 
       "read": true 
      }, 
      "ASPKs6UVwb": { 
       "read": true, 
       "write": true 
      } 
      }, 
      "__type": "Object", 
      "className": "_User" 
     }, 
     "createdAt": "2017-10-27T21:03:35.442Z", 
     "updatedAt": "2017-10-28T15:15:23.556Z", 
     "payment": { 
      "objectId": "nr7ln7U3eJ", 
      "payment_date": { 
      "__type": "Date", 
      "iso": "2017-10-27T23:42:50.614Z" 
      }, 
      "user": { 
      "__type": "Pointer", 
      "className": "_User", 
      "objectId": "ASPKs6UVwb" 
      }, 
      "createdAt": "2017-10-27T23:42:50.624Z", 
      "updatedAt": "2017-10-28T15:12:30.131Z", 
      "valid": "valid", 
      "round": { 
      "objectId": "jF9gqG4ndh", 
      "round_date": { 
       "__type": "Date", 
       "iso": "2017-10-28T15:12:00.027Z" 
      }, 
      "createdAt": "2017-10-28T15:11:00.036Z", 
      "updatedAt": "2017-10-28T15:12:30.108Z", 
      , 
      "ACL": { 
       "*": { 
       "read": true 
       } 
      }, 
      "__type": "Object", 
      "className": "Round" 
      }, 
      "ACL": { 
      "ASPKs6UVwb": { 
       "read": true 
      } 
      }, 
      "__type": "Object", 
      "className": "Payment" 
     }, 
     "ACL": { 
      "ASPKs6UVwb": { 
      "read": true 
      } 
     } 
     } 
    ] 
    } 
} 

您可以看到該回復包含payment.round。

我的問題是以下幾點:

  1. 可以通過Pointer<class>.filed ParseCloud/MongoDB的過濾器?由Pointer<class>.Pointer<class>?是否存在該領域的數據?
  2. 如何在我需要檢查現場存在的情況下解決問題,如果User可以有可能PlayersUser可以有多個Payments

UPD 至於我發現蒙戈應該由「點號」 mongodb query by sub-field 那我做錯了支持篩選?

回答

0

簡短的回答:

  1. 沒有
  2. 簡化您的數據結構

龍答:

點符號可以用來

  • 包括指針文檔,正如您在代碼中所做的那樣,例如, include(keys.user)
  • 過濾器對於田地的性質,例如, {properyA: 1, propertyB: 2}。所有的數據都在字段中,而不是另一個由Parse指針引用的另一個集合中的文檔。

點符號不能用作分析查詢中的過濾器參數。 MongoDB也不支持這種過濾,pointer的概念是Parse而不是MongoDB。在像MongoDB這樣的NoSQL環境中,在查詢語言中使用的表之間沒有關係,因爲它不像SQL數據庫那樣是「關係數據庫」。然而,Parse爲簡單查詢提供了一些SQL的舒適性,其概念爲pointer,compoundQuerymatchesKeyInQuery

如果這還不夠,只需將字段添加到集合中即可。費用可能會在多個集合中具有相同的字段和數據,但具有更快的查詢執行時間的優勢。

尋找正確的數據結構是NoSQL的重要主題之一,因爲沒有一般的權利結構。集合和文件結構基本上設計成關閉之間的權衡:安全

  • 執行性能
  • 查詢必要性/頻率
  • (訪問級別)
  • 和數據存儲大小

它們是液體,可以隨時間變化。由於您的應用程序及其查詢發生變化,如果長期收益高於一次性工作量,您還會更改數據結構。