Deploy ReactiveSearch API as a MongoDB Realm app function with a single command. Clone the reactivesearch-realm-project which contains the command.
Set up an Atlas Search index
You need to create an API key
There are two options for creating an API key in Atlas Cloud. You can either start with an Organization level API key and add that to your project or directly create a project level API key.
Create API key
Organization Member permission is sufficient.
Copy the Public Key and Private Key from the next page.
Go to the Project where this API key should be used. Visit that project’s Access Manager and invite this API key.
Invite the org level API key
The API key needs a Project Owner permission to be able to deploy code to your Realm app.
OR
Create API key
The API key needs a Project Owner permission to be able to deploy code to your Realm app.
Copy the Public Key and Private Key from the next page.
Command to deploy:
node rs-cli --private-api-key $private_key --api-key $public_key --app-id $app_id
Once you have cloned the ReactiveSesearch Realm project and run yarn
or npm install
to install the project dependencies, you can run the following command to deploy the ReactiveSearch API to your project.
where
--private-api-key
refers to the private API key from the above step--api-key
refers to the public API key from the above step--app-id
refers to your Realm App id. You can get this by going to your Project > Realm > Application view.
The output of the deploy command will appear as follows:
Deploying ReactiveSearch API as a Realm function
████████████████████████████████████████ 100% | ETA: 0s | 5/5
Successfully deployed webhook.
Deployed webhook endpoint : https://us-east-1.aws.webhooks.mongodb-realm.com/api/client/v2.0/app/application-3-jrkwf/service/http_endpoint/incoming_webhook/reactivesearch
You can make a test request to this webhook using this curl command
curl -XPOST https://us-east-1.aws.webhooks.mongodb-realm.com/api/client/v2.0/app/application-3-jrkwf/service/http_endpoint/incoming_webhook/reactivesearch \
-H "Content-Type: application/json" \
-d '{
"query": [{
"id": "search",
"dataField": "*",
"size": 5
}],
"mongodb": {
"db": "'"$database"'",
"collection": "'"$collection"'"
}
}'
Deploy with Basic Authentication
The deployment function also comes with built-in support to deploy with Basic Auth enabled. You can pass the plain-text values to use for Basic Auth with the --app-authentication
flag.
node rs-cli --private-api-key $private_key --api-key $public_key --app-id $app_id --app-authentication my-user:my-password
--app-authentication
flag expects username password in a $user:$password format.Go over different search examples that can be run directly with the Realm deployed function over here.
Or jump to with testing the Realm function with a React UI over here.
You can also optionally deploy the search UI using MongoDB Realm’s static hosting feature with one CLI command and a click. Read the Search UI hosting guide over here.