1

Is it possible to use the loopback-connector-mongodb and have extended loopback models use the same collection in mongodb? I'm essentially looking for the same feature as mongoose's model discriminator.

1 Answers1

0

I believe it is possible, however I would reccomend you to do some extensive testing to pinpoint unexpected behaviors with, for example, model relations.

Let's say you had a Women model

{
  "name":"Woman",
  "plural:"Women",
  "options":{
    "mongodb":{
      "collection":"woman"
    },
  },
  "properties":{
    "id":{...},
    "name":{...},
    "status":{...},
    "age":{...}
  }
}

now, you could define a singleWomen model

{
  "name":"singleWoman", 
  "plural":"singleWomen",
  "base":"Woman",
  "scopes":{
    "where":{
      "status":"single"
    }
  }
};

I'm not sure that inserting a new record on singleWoman would enforce the status field to equal "single". I'm pretty sure it won't, so you'll have to add some business logic to patch that behavior.

ffflabs
  • 17,166
  • 5
  • 51
  • 77