TL;博士
ParseCloud / MongoDB可以按
Pointer<class>.filed
过滤吗?通过Pointer<class>.Pointer<class>
?是否存在该领域的数据?
很长的问题:
Round
是将在时间到来时自动播放的对象。
Payment
对象,表示用户付款。付款时,我们会为其设置字段round
。
Player
将在线User
与Payment
我需要在几个条件下查询玩家:
Player
round
且valid
等于&#39;有效&#39;)payment
Player
user
等于特定用户payment
Player
user
等于特定用户round
且valid
等于&#39;有效&#39;)付款除了验证 Payment
查询中的Player
之外,我还做了一切工作。
此列表中的条件 1 。
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 OR 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);
我已经检查过Mongo的日志,他们看起来跟着
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。
我的问题如下:
Pointer<class>.filed
过滤吗?到Pointer<class>.Pointer<class>
?是否存在该数据?User
可以Players
可以检查字段在线状态User
,Payments
可以有多个 public function type($html, $id){
$titletype = $this->XPath($html ,'//ul [@data-sku-prop-id="' . $id . '"]//a [@data-role="sku"]');
$spantype = $this->XPath($html ,'//ul [@data-sku-prop-id="' . $id . '"]//a [@data-role="sku"]/span/text()');
$imagetype = $this->XPath($html ,'//ul [@data-sku-prop-id="' . $id . '"]//a [@data-role="sku"]/img');
if($imagetype->length > 0){
return "image";
}
if($spantype->length > 0){
return "span";
}
if($titletype->length > 0){
return "title";
}
}
public function propertyvalues($html, $id, $propertynames, $propcount){
for($i = 0; $i <= $propcount-1; $i++){
$datatype = $this->type($html, $id[$i]);
echo $datatype;
switch($datatype){
case "image":
$xpath = $this->XPath($html ,'//ul [@data-sku-prop-id="' . $id[$i] . '"]//a [@data-role="sku"]/img');
case "span":
$xpath = $this->XPath($html ,'//ul [@data-sku-prop-id="' . $id[$i] . '"]//a [@data-role="sku"]/span/text()');
case "title":
$xpath = $this->XPath($html ,'//ul [@data-sku-prop-id="' . $id[$i] . '"]//a [@data-role="sku"]');
}
foreach($xpath as $propertyvalue){
switch($datatype){
case "image":
//This is the one that doesn't work, but it does loop through it 3 times(3 images)
$property[] = $propertyvalue->getAttribute("src");
case "span":
$property[] = $propertyvalue->nodeValue;
case "title":
$property[] = $propertyvalue->getAttribute('title');
}
}
$properties[$i] = $propertynames[$i] . " " . implode(", ", $property);
}
return $properties;
}
}
,我该如何解决这种情况。UPD 据我所知,mongo应支持通过&#34;点符号&#34; mongodb query by sub-field 那么我做错了什么?
答案 0 :(得分:0)
简答:
答案很长:
点符号可用于
include(keys.user)
{properyA: 1, propertyB: 2}
。所有数据都在字段中,而不是在Parse指针引用的另一个集合中的另一个文档中。点表示法不能用作Parse查询中引用指针的过滤器参数。 MongoDB也不支持这样的过滤,pointer
的概念是Parse,而不是MongoDB。在像MongoDB这样的NoSQL环境中,在查询语言中使用的表之间没有关系,因为它不是关系数据库&#34;像一个SQL数据库。但是,Parse为简单查询提供了一些SQL的舒适性,其概念为pointer
,compoundQuery
和matchesKeyInQuery
。
如果这还不够,只需将字段添加到集合中即可。以牺牲您在多个集合中可能具有相同字段和数据但具有更快查询执行时间的优势为代价。
找到正确的数据结构是NoSQL的一个重要主题,因为没有一般的正确结构。集合和文档结构基本上是在以下之间进行权衡:
它们是液体,可以随时间变化。当您的应用及其查询发生变异时,如果长期收益大于一次性工作,您也会更改数据结构。