How to pass {useMasterKey: true} to a parse-server js aggregate query? - mongodb

I want to do an aggregate query using parse-server js.
Something of the style of the following code, but instead of using .find(), using .aggregate(pipeline, options).
const query = new Parse.Query("myClass");
query.find().then( // ... do something with the resulting objects)
)
According to the docs (https://parseplatform.org/Parse-SDK-JS/api/v1.11.0/Parse.Query.html#aggregate), aggregate requires the masterkey to be used. However, the options parameter of the call to .aggregate(pipeline, options) does not allow for the passing of an object that has the field to use the masterkey defined.
The workarounds found online suggest the use of Parse.Cloud.useMasterkey, which has been deprecated.

You must set the master key during the initialization of your Parse SDK. At some point in your code you probably initialize the connection with the Parse Server using a code similar to this:
Parse.serverURL = 'http://url_to_parse_server.com'
Parse.initialize('appId')
What you have to do is to pass two new parameters in the .initialize function above. The second parameter is a key to use the JS SDK, but if didn't set this key in your Parse Server then you can pass null in this parameter.
The third parameter is what you are looking for and here is where you will put the master key. Like this:
Parse.initialize('appId', null, 'master key')
After you do that all the API calls that require the master key, like aggregate will use it automatically.

There are actually two libraries at play here. Firstly, there is Parse Server - where they requirement for the use of the MasterKey is coming from.
Then there is the Parse JS SDK (to which your documentation link points) - which is the environment which Cloud Code uses to talk to Parse Server.
If you look at the source code for the aggregate function in the JS SDK, it appears that they set the MasterKey automatically: https://github.com/parse-community/Parse-SDK-JS/blob/8a69f9504f398187a856797c4b037b8eb6804dd8/src/ParseQuery.js#L763
So your query should just work, without you having to set the MasterKey explicitly from the JS SD call.

Related

React hook form dynamic fields validations

My task is to implant a functionality that includes dynamically creation of fields and apply validation on those dynamically created fields.
I have found a prefect example that fits my use case which is here (https://stackblitz.com/edit/react-hook-form-dynamic-form-example) but the issue that I am facing is every time I try to download the example from stackblitz and run locally I get error below error:
{"tickets":{"message":"tickets must be a `array` type, but the final value was: `null` (cast from the value `{\n \"0name\": \"\\\"\\\"\",\n \"0email\": \"\\\"\\\"\",\n \"1name\": \"\\\"\\\"\",\n \"1email\": \"\\\"\\\"\"\n}`).\n If \"null\" is intended as an empty value be sure to mark the schema as `.nullable()`","type":"typeError"}}
I am wondering if someone could help me run this example locally, rest I can work out.
Many thanks :)

Question regarding parameter store and Cloud formation integration

I was trying this scenario but I am not able to figure out
I have a name and value in parameter store in SSM, now I am running the CF template from CLI using code pipeline, and I want the CF template take values directly from parameter store and should not prompt
on screen asking me to give the value.
I tried this but it prompt me .
AWS::SSM::Parameter::value
this is prompting when I used to upload a template in screen. how to avoid it and make the script take the value from parameter store directly
You have two choices for that:
Provide a default value for the parameter.
Use ParameterOverrides in your CodePiepline to provide the required value for the parameter.

How to generate and resolve custom URLs with TYPO3 9.5

Am using $GLOBALS['TSFE']->cObj->typoLink to generate a link and I've an additional parameter like this: ext__pluginname[d64]=31511 and would like to return something like a/b/c. I would then want TYPO3 to give me back the link so I can resolve it when clicked. I've already tried PersistedAliasMapper but won't allow to return anything with a slash in it. I've even tried a custom aspect mapper. I get the error:
Parameter "tx_ext__pluginname__d64" for route "enhancer_tx_ext__pluginname000000003e62d21a000000000514759a" must match "[^/]++" ("a/c" given) to generate a corresponding URL.
Am able to generate and resolve the slugs(urls). I can store them in db and retrieve them for that matter. No problem.
Am generating them from root page (uid 1).
How can i get this to work?
I assume you already have created the desired path in a database table or view already, making use of the slug feature in the TYPO3 backend or creating it yourself.
You could then use the PersistedAliasMapper in your site config (config/sites/default/config.yaml).
If you need multiple values in a single path divided by slashes (not a combined slug field), take a look at the route configuration for the news extension. You just have to use database mappers instead of static ones, but keep in mind this may impact the performance of the routing!
As you did not provide much detail about your use case, I don't really understand why you need such a path structure with slashes.

Using sails and waterline, where is the showJoins option set when using toObject()?

Using the Model.toObject() call , I saw that all association keys were being stripped. Looking through the documentation, it seems there's a showJoin option as well as a joins[] array of keys to include.
But, I haven't found a place where to send in or set those options. Anyone know?

Custom Search Results in REST MarkLogic

So new to MarkLogic am stuck and not finding the documentation of use. I know what i need to do, just do not know how to do it.
I have a keyvalue? search on my REST server which returns ML's standard search results and XML snippet. I want to create my own custom search result which will output a title element for my XML files.
I am aware that i need to create an XSLT transformation document and upload that to the server but do not know how to target ML's search function or how to write this out.
I have basic knowledge of XSLT, if i just created something that targets each files title using xPath will this work, or does ML require use of their custom functions?
I know its a bit broad, but hopefully someone can point steer me.
Sounds like you are talking about the GET /v1/keyvalue endpoint of MarkLogic REST API. Unfortunately that does not allow you to choose a transform. You can probably use GET /v1/search with a transform param instead though, using a structured query for an element value query. The docs contain a good syntax reference on that.
Docs on creating and managing transforms can be found here:
http://docs.marklogic.com/guide/rest-dev/transforms#chapter
HTH!
You can use extract-metadata in your search options with search:search or the /v1/search/ REST API endpoint to include the title element in a metadata element or JSON property in your results:
import module namespace search = "http://marklogic.com/appservices/search"
at "/MarkLogic/appservices/search/search.xqy";
search:search(
"my query string",
<options xmlns="http://marklogic.com/appservices/search">
<extract-metadata>
<qname elem-ns="" elem-name="title"/>
</extract-metadata>
</options>)
If you need more flexibility, you specify a custom snippet implementation or a results decorator function in your search options.
Is this key-value or full text? For key-value you could use XPath. Any XPath that starts with / or // or fn:collection() or fn:doc() will search the entire database. You can search specific document(s) or collection(s) too.
For full text you'd probably want to use https://docs.marklogic.com/search:search - or possibly https://docs.marklogic.com/cts:search for really low-level control.
There's some example code using search:search from XSL at https://github.com/marklogic/RunDMC which might help. It doesn't use the REST API: it's a traditional form-submit web page. But the view/search.xsl code might give you some idea how to call the search API from XSLT.
That RunDMC code might also help you if you need to call XSL from XQuery: take a look at controller/transform.xqy.