iT邦幫忙

第 12 屆 iThome 鐵人賽

DAY 9
1

Mongodb

以 Mongodb 為範例

  $ 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

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

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


上一篇
Authorization - Part II
下一篇
Frond End - Storage part I
系列文
I Shot You 不小心30
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言