Vins Vins - 1 month ago 11
Javascript Question

Parse server query each with useMasterKey parameter

I'm migrating from Parse to Parse server. Most of my code is made without promises.
For this to work, I have to send the parameter:

useMasterKey: true
(where necessary) for each query / save.

For find and get queries or fetch objects, I have no problems, example:

Parse.com (find)

query.find({
success: function(results) {
//...


Parse Server (find)

query.find({useMasterKey: true
}).then(function(results) {
//....


Parse.com (fetch)

user.fetch({
success: function(user) {
//...


Parse Server (fetch)

user.fetch({useMasterKey: true,
success: function(user) {
//....


The problem is with each functions:

Parse.com (each)

query.each(function(comment) {
//...


Parse Server (each)

query.each({useMasterKey: true
}).then(function(comment) {
//....


It does not work.

Thanks

Answer

Although the docs don't suggest that the useMasterKey option is supported for an each query, having tested and verified myself it is in fact possible. Syntax as follows:

query.each(callback, {useMasterKey: true})

Where callback is a function that is called for each result of the query.