2014-07-13 3 views
1

내 모델을 정의하기 위해 백 엔드에서 mongoose를 사용하고 있습니다. 프론트 엔드에서 breezeJS가 메타 데이터에 대해 알리고 싶습니다.mongoose 모델에서 breezejs 메타 데이터로

mongoose로 정의 된 스키마에서 메타 데이터를 만들 수있는 방법이 있습니까?

답변

1

나는이 문제

https://www.npmjs.org/package/breeze-mongoose

//Create a function that returns a mongoose model 

var mongoose = require('mongoose'), 

    dbConnection = mongoose.createConnection(mongodb_connection_string), 

    modelContainer = function getModel(model){ // the name of the model 
    return dbConnection .model(model); 
    }, 

    dbSchemas = dbConnection.models; 

//Add the getMetadata endpoint to your API 

    var breezeMongoose = require('breeze-mongoose')(modelContainer); 

    app.get('breeze/metadata', function(req, res){ 
     res.json(breezeMongoose.getMetadata(dbSchemas)); 
    }) 

//Add the saveChanges endpoint 

app.post(function(req, res){ 
     breezeMongoose.saveChanges(req.body) 
      .then(function(saveResults){ 
      res.json(saveResults); 
     }) 
     .catch(function(message){ 
      res.send(500, message); 
     }); 
    }); 
을 다루는 작은 NPM 패키지를 작성하는 시도
관련 문제