How to create MongoDB collections based on my models? Arc's "Migrate model" button does nothing

291 views
Skip to first unread message

86tfv987

unread,
Oct 31, 2015, 5:01:10 AM10/31/15
to LoopbackJS
From the docs I cannot understand how to create MongoDB collections based on my models.

I have created models using $ slc loopback:model tool.
Now I want Loopback to create corresponding MongoDB collections.

One of the models is a Client model whose base class is a User model. That means that client/models/client.json is just empty! 
{
 
"name": "Client",
 
"plural": "Clients",
 
"base": "User",
 
"idInjection": true,
 
"properties": {},
 
"validations": [],
 
"relations": {},
 
"acls": [],
 
"methods": []
}

I don't know what properties my Client model has because it inherits all the properties from built-in User model which are hidden somewhere. It means I cannot even create MongoDB collection manually!

Docs says:
StrongLoop Arc enables you to perform auto-migration without coding.

Ok, I follow the link and it says:

Click the Migrate Model button to create a database table for each model in your application, with a column for each model property.  This is called LoopBack auto-migration.
 
Ok, I click "Migrate Model". Some process starts informing me "Migrating...", then small pop-up window appears that says: "model migrated" but when I check my MongoDB database there are no any collections created. So what was migrated? What model was migrated? Why does it inform that model was migrated but actually it wasn't.

My question is:
How to create MongoDB collections based on my models? How with this framework can I perform auto-migration?
 

Amirudin Mohamed Ghani

unread,
Nov 2, 2015, 11:51:35 AM11/2/15
to loopb...@googlegroups.com
Hi

Here is a steps to create MongoDB collections base on built-in/custom models generated vial SL CLI (tested and work for me).

  1. Install Mongodb server/service [https://www.mongodb.org/downloads#production]
  2. Next, install MongoDB connector [$ npm install loopback-connector-mongodb]
  3. Next, generate datasource [$ slc loopback:datasource] ... Choose MongoDB when prompt
  4. Next, generate model [$ slc loopback:model] ... Choose data-source at step#3 when prompt
  5. To confirm all properties generated as expected, visit Arc Composer [$ slc arc ] /composer

To learn about available fields inherited from built-in user model, visit here [ https://apidocs.strongloop.com/loopback/#user ]


Important notes on using Auto-Migrate

Auto-migrate: Automatically create or re-create the table schemas based on the model definitions.

Auto-migration will drop an existing table if its name matches a model name. When tables with data exist, use auto-update to avoid data loss.


To use Migrate Model button


1- Open model in SL Composer




2- Choose new Datasource (e.g moving to MongoDB to MySQL)



3- Click 'Save Model' (IMPORTANT) then click 'Migrate Model'





Hope that helps!



Cheers.

Reply all
Reply to author
Forward
0 new messages