所以大家好,和我有同样问题的人......我想通了!因此,首先,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();