Search code examples
mongodbcollectionsloopbackjsloopback

Cannot connect loopback model to mongo db collection


I have a mongo db collection named like "name.types". When I am creating model for the collection in loopback, I cannot enter the model name with the "." as it says special characters not allowed. So I created the model as "name_types". Now how can I connect this model to the collection "name.types"? Any help would be appreciated. Thanks!


Solution

  • You can set collection name in model.json file :

    //model.json
    
    ...
    "options": {
        "validateUpsert": true,    
        "mongodb": {
          "collection": "name_types"
        }
      },
    ....