https://github.com/mother/socket.io-adapter-mongo
https://github.com/mother/socket.io-adapter-mongo
Last synced: about 2 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/mother/socket.io-adapter-mongo
- Owner: mother
- Created: 2017-10-18T17:25:33.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2022-12-07T17:29:45.000Z (over 2 years ago)
- Last Synced: 2025-04-02T00:37:39.768Z (about 2 months ago)
- Language: JavaScript
- Size: 172 KB
- Stars: 5
- Watchers: 2
- Forks: 5
- Open Issues: 11
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# socket.io-adapter-mongo
[](https://travis-ci.org/mother/socket.io-adapter-mongo)
## Installing
```sh
npm install @mother/socket.io-adapter-mongo --save
```## How to use
```js
const io = require('socket.io')(3000);
const mongoAdapter = require('@mother/socket.io-adapter-mongo');
io.adapter(mongoAdapter('mongodb://localhost/test'));
```or pass an object:
```js
const io = require('socket.io')(3000);
const mongoAdapter = require('@mother/socket.io-adapter-mongo');io.adapter(mongoAdapter({
uri: 'mongodb://localhost/test',
key: 'socket.io',
mOptions: {
tls: true
}
}));
```By running socket.io with the `socket.io-adapter-mongo` adapter you can run
multiple socket.io instances in different processes or servers that can
all broadcast and emit events to and from each other.If you need to emit events to socket.io instances from a non-socket.io
process, you should use [socket.io-emitter](https://github.com/socketio/socket.io-emitter).## API
### adapter(uri[, opts])
`uri` is a a mongodb:// uri string
If using this method of calling the adapter, the uri string will used instead of the uri property in the options object.
For a list of options see below.
### adapter(opts)
The following options are allowed:
- `uri`: mongodb:// uri string this property or the `mongoose` property are **required**.
- `key`: the name of the key to pub/sub events on as prefix (`socket.io`)
- `collectionName`: the name of the capped collection to be used (`socket.io-message-queue`)
- `collectionSize`: the size of the capped collection to be used, in bytes (`1000000`) (10mb)
- `mongoose`: an existing Mongoose instance that can be used instead of a mongodb:// uri
- `mOptions`: options to pass to Mongoose## Notes
The following options are passed to Mongoose by default:
- `useNewUrlParser`: true
- `useUnifiedTopology`: trueIf you want to override these options, just include them in `mOptions`.
## License
MIT