简体   繁体   中英

load mongoose model from other controller in yeoman angular-fullstack project

I am writing an application using yeoman angular-fullstack, I defined some entities that I would like to access from other entities controller. For example I have in my server->api->Mall I have the following code:

var MallSchema = new Schema({
  ...
});

module.exports = mongoose.model('Mall', MallSchema);

in other Business controller I would like to search for Mall by _id, using mongoose, But I can not import MallSchema trying to do the following:

mall = mongoose.models("MallSchema").find({_id: "some_mall_id"})
business.mallType = mall.type
business.update();

or nesting Schema's

var MallSchema = new Schema({
  business : Business;
});

I really tried in lot of ways, ending up with frustration, googling this yields lots of answers, none have works and few just seems too complicated like this one , I newbie to node.js so I mast been missing somthing simple. any help would be nice for the entire community.

it seems simple but somehow missed from documentation this seems to work for me now

var business = require('../business/business.model')();
var user = require('../user/user.model')()

Hope it helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM