SociekCluster-Storage

Mongodb

以 Mongodb 為範例

1
2
3
4
$ git clone git@github.com:SocketCluster/scc-broker.git scc-mongo-broker && cd scc-mongo-broker
$ yarn install
$ yarn add mongoose dotenv
$ mkdir models

models/tankModel.js

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
const mongoose = require('mongoose');
const { Schema } = mongoose;

const schema = new mongoose.Schema({ name: 'string', size: 'string' });
const Tank = mongoose.model('Tank', schema);
// Tank.create({ size: 'small' }, function (err, small) {
// if (err) return handleError(err);
// // saved!
// });


Tank.find().then(result => {
console.log('AL: result', result)
}).catch(error => {
console.log('AL: error', error)
})

module.exports = Tank;

server.js

1
2
3
4
5
6
7
8
9
10
11
const dotenv = require('dotenv');
dotenv.config();
const mongoose = require('mongoose');

const uri = 'mongodb://localhost:27017/test?poolSize=4';
mongoose.connect(uri, {useNewUrlParser: true, useUnifiedTopology:true});
// mongoose.createConnection(uri, {useUnifiedTopology: true});

const Tank = require('./models/tankModel');
dotenv.config();

參考資料

mongoose

scc-broker

sc-redis

sc-rabbitmq

sc-error

文章目录
  1. 1. Mongodb
  2. 2. 參考資料
|