Setting up the backend

Starting the backend services

In order to have realtime search running we need:

  • deepstream server
  • mongodb server
  • mongodb replicate (for changefeeds to be enabled)
  • realtime-search

Due to the slightly more complex nature of the backend we will let docker-compose manage everything by just using the following commands:

git clone https://github.com/deepstreamIO/deepstream.io-realtime-search.git
cd deepstream.io-realtime-search/example
docker-compose up

Which would result in all the four images being pulled down and run, with deepstream port exposed on 6020

To look a little deeper into it, you’ll see that:

  • We have a deepstream config.yml file for mongodb configuration:

serverName: realtime-search-example

record:
  # I would recommend excluding any object generated via listening from storage objects from storage
  # since they can usually be computed
  storageExclusionPrefixes:
    - deepstream_search/

storage:
  name: mongodb
  options:
    connectionString: ${MONGO_URL}
    database: ${MONGO_DATABASE}
    splitChar: /

permission:
  type: config
  options:
    # Permissions file
    permissions: fileLoad(permissions.yml)
    # Amount of times nested cross-references will be loaded. Avoids endless loops
    maxRuleIterations: 3
    # PermissionResults are cached to increase performance. Lower number means more loading
    cacheEvacuationInterval: 60000

# Authentication
auth:
  - type: file
    options:
      # Path to the user file. Can be json, js or yml
      users: fileLoad(users.yml)

  - type: none

  • A docker compose file + a mongodb script which sets up deepstream, realtime search, mongodb and a mongodb replica (all using the default images):

version: '3.3'
services:
  mongo:
    image: mongo:3.6.8
    ports:
      - 27017:27017
    command: mongod --storageEngine wiredTiger --smallfiles --replSet rs0 --logpath=/dev/null # --quiet

    # this exists to configure the mongo instance to act like a single-node
    # replica set. This is needed to get an oplog collection running so that we can
    # tail it to keep deepstream in sync. Once the replica set is running,
    # this container will exit peacefully.
  database-replica-set:
    image: mongo:3.6.8
    volumes:
      - ./scripts:/scripts
    entrypoint: ['/scripts/local-replica-set.sh']
    depends_on:
      - mongo

  deepstream:
    image: deepstreamio/deepstream.io:latest
    command: 'deepstream start -c /etc/deepstream/conf/config.yml'
    environment:
      - MONGO_URL=mongodb://mongo/deepstream
      - MONGO_DATABASE=deepstream
      - DEEPSTREAM_PASSWORD=deepstream_password
    volumes:
      - ./conf:/etc/deepstream/conf:ro
    ports:
      - 6020:6020
    depends_on:
      - mongo

  realtime-search:
    image: deepstreamio/realtime-search:latest-alpine
    command: 'mongo'
    environment:
      - DEEPSTREAM_URL=ws://deepstream:6020
      - DEEPSTREAM_PASSWORD=deepstream_password
      - MONGO_DATABASE=deepstream
      - MONGO_URL=mongodb://mongo/deepstream
      - MONGO_PRIMARY_KEY=ds_key
    depends_on:
      - deepstream
      - mongo

Once you run docker-compose up that should be it for the backend!

You can also look at all the CLI commands by running

> docker run deepstreamio/realtime-search mongo --help

Usage: provider mongo [options]

start a mongodb realtime search provider

Options:
  --mongo-url <mongo-url>            Connect to this mongo server
  --mongo-database <mongo-database>  Name of mongo database
  --ds-url <ds-url>                  Connect to this deepstream server
  --logger-type <logger-type>        Log messages with pino or to std
  --log-level <level>                Log messages with this level and above
  --collection-lookup <fileName>     JSON file containing model lookups
  --inspect <url>                    Enable node inspector
  --native-query                     Use native mongodb query syntax
  -h, --help                         output usage information