0

所以,如果我使用我的 DeepStream 服务器如下

const {Deepstream} = require('@deepstream/server')

const server = new Deepstream({

server.start()

它工作得很好我可以从我的前端应用程序连接到它,如下所示

const {DeepstreamClient} = require('@deepstream/client')
const client = new DeepstreamClient('192.168.88.238:6020')
client.login()

但如果我添加 MongoDB 存储实例或 RethinkDB NPM - RethinkDB

const {Deepstream} = require('@deepstream/server')

const server = new Deepstream({
    storage: {
        name: 'rethinkdb',
        options: {
            host: 'localhost',
            port: 28015
        }
    }
})

// start the server
server.start()

尝试访问我的 ds 服务器时收到以下错误消息。(我也尝试通过 WSS:// 而不是 WS:// 进行连接) 在此处输入图像描述

4

1 回答 1

0

所以大家好,和我有同样问题的人......我想通了!因此,首先,npm 包文档从Mongo DB驱动程序的使用中所说的完全没有数据

所以他们说你应该如何使用 npm 包:

var Deepstream = require( 'deepstream.io' ),
    MongoDBStorageConnector = require( 'deepstream.io-storage-mongodb' ),
    server = new Deepstream();
 
server.set( 'storage', new MongoDBStorageConnector( {
  connectionString: 'mongodb://test:test@paulo.mongohq.com:10087/munchkin-dev',
  splitChar: '/'
}));
 
server.start();

而不是这一切!

你真的不需要,'deep stream.io-storage-MongoDB'因为它是一个旧模块(基于在此处输入图像描述:),你真的不需要使用这种方式......

MongoDB连接器的正确用法:

const {Deepstream} = require('@deepstream/server');
const server = new Deepstream({
    storage: {
        name: "mongodb",
        options: {
            connectionString: MONGO_CONNECTION_STRING ,
            splitChar: '/'
        }
    }
});

server.start();

或者你也可以创建一个配置。yaml 文件来自所有这些:

storage:
  name: mongodb
  options:
    connectionString: 'MONGO_CONNECTION_STRING'
    # optional database name, defaults to `deepstream`
    database: 'DATABASE_NAME'
    # optional table name for records without a splitChar
    # defaults to deepstream_docs
    defaultCollection: 'COLLECTION_NAME'

    # optional character that's used as part of the
    # record names to split it into a table and an id part
    splitChar: '/'

并将其传递给深层流构造函数,如下所示:

const {Deepstream} = require('@deepstream/server');
const server = new Deepstream('config.yaml');

server.start();
于 2021-07-22T08:46:55.687 回答