Skip to content

Commit 6bf6597

Browse files
authored
Read preference (#635)
* Completing read preference example in cloud code section * Read preferences for get operation in rest guide * Read preference for queries on rest guide * Read preference for js sdk * Read preference for PHP queries * Improving text including 'argument'
1 parent c54b417 commit 6bf6597

File tree

6 files changed

+110
-10
lines changed

6 files changed

+110
-10
lines changed

_includes/cloudcode/cloud-code.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,7 @@ Parse.Cloud.beforeFind('MyObject', (req) => {
381381
Parse.Cloud.beforeFind('MyObject2', (req) => {
382382
req.readPreference = 'SECONDARY_PREFERRED';
383383
req.subqueryReadPreference = 'SECONDARY';
384+
req.includeReadPreference = 'PRIMARY';
384385
});
385386

386387
```

_includes/js/queries.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -537,3 +537,15 @@ query.distinct("age")
537537
// There was an error.
538538
});
539539
```
540+
541+
## Read Preference
542+
543+
When using a MongoDB replica set, you can use the `query.readPreference(readPreference, includeReadPreference, subqueryReadPreference)` function to choose from which replica the objects will be retrieved. The `includeReadPreference` argument chooses from which replica the included pointers will be retrieved and the `subqueryReadPreference` argument chooses in which replica the subqueries will run. The possible values are `PRIMARY` (default), `PRIMARY_PREFERRED`, `SECONDARY`, `SECONDARY_PREFERRED`, or `NEAREST`. If the `includeReadPreference` argument is not passed, the same replica chosen for `readPreference` will be also used for the includes. The same rule applies for the `subqueryReadPreference` argument.
544+
545+
```javascript
546+
query.readPreference(
547+
'SECONDARY',
548+
'SECONDARY_PREFERRED',
549+
'NEAREST'
550+
);
551+
```

_includes/php/queries.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -455,3 +455,15 @@ $monster = Monster::spawn(200);
455455
echo monster->strength(); // Displays 200.
456456
echo monster->hasSuperHumanStrength(); // Displays true.
457457
```
458+
459+
## Read Preference
460+
461+
When using a MongoDB replica set, you can use the `$query->readPreference(readPreference, includeReadPreference, subqueryReadPreference)` function to choose from which replica the objects will be retrieved. The `includeReadPreference` argument chooses from which replica the included pointers will be retrieved and the `subqueryReadPreference` argument chooses in which replica the subqueries will run. The possible values are `PRIMARY` (default), `PRIMARY_PREFERRED`, `SECONDARY`, `SECONDARY_PREFERRED`, or `NEAREST`. If the `includeReadPreference` argument is not passed, the same replica chosen for `readPreference` will be also used for the includes. The same rule applies for the `subqueryReadPreference` argument.
462+
463+
```javascript
464+
$query->readPreference(
465+
"SECONDARY",
466+
"SECONDARY_PREFERRED",
467+
"NEAREST"
468+
);
469+
```

_includes/rest/objects.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,33 @@ print result
165165
</code></pre>
166166
</div>
167167

168+
When using a MongoDB replica set, you can use the `readPreference` option to choose from which replica the object will be retrieved. You can also use the `includeReadPreference` option to choose from which replica the included pointers will be retrieved. The possible values for both options are `PRIMARY` (default), `PRIMARY_PREFERRED`, `SECONDARY`, `SECONDARY_PREFERRED`, or `NEAREST`. If the `includeReadPreference` option is not set, the same replica chosen for `readPreference` will be also used for the includes.
169+
170+
<div class="language-toggle">
171+
<pre><code class="bash">
172+
curl -X GET \
173+
-H "X-Parse-Application-Id: <span class="custom-parse-server-appid">${APPLICATION_ID}</span>" \
174+
-H "X-Parse-REST-API-Key: <span class="custom-parse-server-restapikey">${REST_API_KEY}</span>" \
175+
-G \
176+
--data-urlencode 'include=game' \
177+
--data-urlencode 'readPreference=SECONDARY' \
178+
--data-urlencode 'includeReadPreference=SECONDARY_PREFERRED' \
179+
<span class="custom-parse-server-protocol">https</span>://<span class="custom-parse-server-url">YOUR.PARSE-SERVER.HERE</span><span class="custom-parse-server-mount">/parse/</span>classes/GameScore/Ed1nuqPvcm
180+
</code></pre>
181+
<pre><code class="python">
182+
import json,httplib,urllib
183+
connection = httplib.HTTPSConnection('<span class="custom-parse-server-url">YOUR.PARSE-SERVER.HERE</span>', 443)
184+
params = urllib.urlencode({"include":"game","readPreference":"SECONDARY","includeReadPreference":"SECONDARY_PREFERRED"})
185+
connection.connect()
186+
connection.request('GET', '<span class="custom-parse-server-mount">/parse/</span>classes/GameScore/Ed1nuqPvcm?%s' % params, '', {
187+
"X-Parse-Application-Id": "<span class="custom-parse-server-appid">${APPLICATION_ID}</span>",
188+
"X-Parse-REST-API-Key": "<span class="custom-parse-server-restapikey">${REST_API_KEY}</span>"
189+
})
190+
result = json.loads(connection.getresponse().read())
191+
print result
192+
</code></pre>
193+
</div>
194+
168195
## Updating Objects
169196

170197
To change the data on an object that already exists, send a PUT request to the object URL. Any keys you don't specify will remain unchanged, so you can update just a subset of the object's data. For example, if we wanted to change the score field of our object:

_includes/rest/queries.md

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1157,3 +1157,51 @@ print result
11571157
</div>
11581158

11591159
You can also constraint by `limit`, `skip`, `sort`.
1160+
1161+
## Read Preference
1162+
1163+
When using a MongoDB replica set, you can use the `readPreference` option to choose from which replica the objects will be retrieved. You can also use the `includeReadPreference` option to choose from which replica the included pointers will be retrieved and the `subqueryReadPreference` option to choose in which replica the subqueries will run. The possible values these options are `PRIMARY` (default), `PRIMARY_PREFERRED`, `SECONDARY`, `SECONDARY_PREFERRED`, or `NEAREST`. If the `includeReadPreference` option is not set, the same replica chosen for `readPreference` will be also used for the includes. The same rule applies for the `subqueryReadPreference` option.
1164+
1165+
<div class="language-toggle">
1166+
<pre><code class="bash">
1167+
curl -X GET \
1168+
-H "X-Parse-Application-Id: <span class="custom-parse-server-appid">${APPLICATION_ID}</span>" \
1169+
-H "X-Parse-REST-API-Key: <span class="custom-parse-server-restapikey">${REST_API_KEY}</span>" \
1170+
-G \
1171+
--data-urlencode 'where={"post":{"$inQuery":{"where":{"image":{"$exists":true}},"className":"Post"}}}' \
1172+
--data-urlencode 'include=post' \
1173+
--data-urlencode 'readPreference=SECONDARY' \
1174+
--data-urlencode 'includeReadPreference=SECONDARY_PREFERRED' \
1175+
--data-urlencode 'subqueryReadPreference=NEAREST' \
1176+
<span class="custom-parse-server-protocol">https</span>://<span class="custom-parse-server-url">YOUR.PARSE-SERVER.HERE</span><span class="custom-parse-server-mount">/parse/</span>classes/Comment
1177+
</code></pre>
1178+
<pre><code class="python">
1179+
import json,httplib,urllib
1180+
connection = httplib.HTTPSConnection('<span class="custom-parse-server-url">YOUR.PARSE-SERVER.HERE</span>', 443)
1181+
params = urllib.urlencode({
1182+
"where":json.dumps({
1183+
"post": {
1184+
"$inQuery": {
1185+
"where": {
1186+
"image": {
1187+
"$exists": True
1188+
}
1189+
},
1190+
"className": "Post"
1191+
}
1192+
}
1193+
}),
1194+
"include":"post",
1195+
"readPreference":"SECONDARY",
1196+
"includeReadPreference":"SECONDARY_PREFERRED",
1197+
"subqueryReadPreference":"NEAREST"
1198+
})
1199+
connection.connect()
1200+
connection.request('GET', '<span class="custom-parse-server-mount">/parse/</span>classes/Comment?%s' % params, '', {
1201+
"X-Parse-Application-Id": "<span class="custom-parse-server-appid">${APPLICATION_ID}</span>",
1202+
"X-Parse-REST-API-Key": "<span class="custom-parse-server-restapikey">${REST_API_KEY}</span>"
1203+
})
1204+
result = json.loads(connection.getresponse().read())
1205+
print result
1206+
</code></pre>
1207+
</div>

assets/js/bundle.js

Lines changed: 10 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)