Friday 15 May 2015

mongoose populate different database -


I have two databases in my program to save users and roles and one for the rest.

1) My model user has a reference to the roles. So I can do the roles by doing the following:

  User.find ({}) populate ('local.roll'). Sort ({email: 1}). Exec (function (mistake, user) {...  

This works right and I can get a user and their roles

2) When I try to do this, but with models that belong to any other database, I get a notorious error:

"Missingcache error: the model is not registered for schema ..."

When I use a different connection, then I I code the code:

  var mongoose = expected ('mongos'); // var configScrwebDB = is required to define another Manguez connection ('./../../config / scrwebDatabase.js'); Var Scrabbed BBExction = Mongoose SecureNet Connection (configsraft bdb.); Var aseguradoSchema = mongoose.Schema ({nombre: {type: string}, abreviatura: {type: string}, rif: {type: string}, direccion: {type: string}}); Module Exports = ScrabbedBCaction.Model ('Aseguurado', Acegurodachema); 3) It is that I have some 'populated' fields in my query (and which failed with the above error):     > 
  var query = Riesgo.find ({cia: filtroObject.ciaSeleccionada}); Query.populate ('asegurado'); Query.sort ("codigo"); Query.select ("codigo fechaInicio estado moneda"); Query.exec (function (err, riesgos) {...  

Of course this is in another JS file; and I

As I said earlier, when models use 'default' monogos connections then I can be populated.

Any ideas how I should correct it will be appreciated. I am missing some obvious point here?

Thanks and goodbye ...

I had only one error. You can use:

var query = Riesgo.find ({cia: filtroObject.ciaSeleccionada}); popup ('asegurado', 'field to retrieve', user); // ** to user The file needs to be defined as a variable that defines the user model. ** query.sort ("codigo"); query

view the link:

Select
("codigo fechaInicio estado moneda");

No comments:

Post a Comment