小编pwb*_*ich的帖子

将子文档添加到现有mongodb文档

本质上,我只是尝试将新的子文档添加到具有以下模式的现有mongodb文档中

/models/server/destination.js

// this is the "destination" model for mongoose
var mongoose = require('mongoose')
var Adventure = require('../models/adventure')

// this is the schema that every entry will get when a new trip is made.
var tripSchema = mongoose.Schema({
    name: { type: String, required: true },
    city: { type: String, required: true },
    dateStart: { type: Date, required: true },
    dateFinish: { type: Date, required: true },
    adventures: [Adventure]
})

// module.exports makes this model available to other file 
module.exports = …
Run Code Online (Sandbox Code Playgroud)

addchild mongoose mongodb mean-stack mongoose-schema

13
推荐指数
1
解决办法
3393
查看次数

node.js的API网关示例

寻找有关如何为微服务应用程序实现节点API网关的好示例,我了解拥有网关的目的,只是不确定如何在不添加另一级RESTful路由调用的情况下实现此网关。对我来说,网关应该只是将路由定向到微服务。

API网关端口3000

router.use('/microservicename/*', function (req, res, next) {
     **code that will direct to microservice**
});
Run Code Online (Sandbox Code Playgroud)

Microservice1 server.js端口3001

var express = require('express');
var app = express();

var routes = require('./routes/routes');

app.use('/microservicename', routes);

var server = app.listen(3001, function () {
    console.log('Server running at http://127.0.0.1:3001/');
});
Run Code Online (Sandbox Code Playgroud)

Microservice1 router.js(3001)

router.get('/route1', function (req, res, next) {
  //get route code
});

router.post('/route2', function (req, res, next) {
  //post route code
});

router.put('/route3', function (req, res, next) {
  //put route code
});

router.delete('/route4', function (req, res, next) …
Run Code Online (Sandbox Code Playgroud)

node.js microservices

5
推荐指数
1
解决办法
3824
查看次数