Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

the lb4 datasource can't create a database automatically in mongoDB #8809

Closed
Barnette-ao opened this issue Aug 9, 2022 · 2 comments
Closed

Comments

@Barnette-ao
Copy link

Describe the bug

Desciption of the bug

when I want create a datasource to connect with mongoDB database,then I read the document ,I enter the lb4 datasource in the CLI. when I finish the creation of the datasource, the .datasource.ts file as follows:

const config = {
  name: 'db',
  connector: 'mongodb',
  url: 'mongodb://localhost:27017/testdb',
  host: 'loaclhost',
  port: 27017,
  user: '',
  password: '',
  database: 'testdb',
  useNewUrlParser: true
};

Expect

I expect after I finish the creation of the datasource,the testdb will automatically created in the MongoDB.

Actual

when I exeute the mongod.exe, and open the CLI, then
input:

show dbs

the output is :

3dcmsT     0.000GB
admin      0.000GB
config     0.000GB
local      0.000GB
vote_rule  0.001GB

there is no testdb as I expected!!!

what should I do to use lb4 datasource to connect the MongoDB server?

when I using loopback 3 to enter lb datasource ,the loopback will create the database automatically ,and I check the mongoDB,I also can see the new database when I define in the config.

but when I use loopback 4 to do the same thing,it is not work?!

It there angthing additional I should know to get my expection done ?

Logs

No response

Additional information

No response

Reproduction

https://codesandbox.io/s/nifty-wilson-4u0mdy

@Barnette-ao Barnette-ao added the bug label Aug 9, 2022
@achrinza
Copy link
Member

achrinza commented Aug 10, 2022

LoopBack 4 does not perform auto-migration on every startup. On most projects ,npm run migrate can be used to run auto-update. The --rebuild flag can be used to perform a full, destructive auto-migrate.

See https://loopback.io/doc/en/lb4/Database-migrations.html and the scaffold-ed src/migrate.ts for more details.

@achrinza achrinza removed the bug label Aug 10, 2022
@Barnette-ao
Copy link
Author

OK,and I check the document again,and find that the repository is the essential part of connetor of mongoDB,as for when I use lb4 datasource to create a connector configuration file ,then it will indeed not create an database automatically!

and after I create a controller of a test model ,then I post an data instance of it.

as a result, when I check the db list in mongoDB CLI,the new database shows in the list.

in conclusion, the database will not create before there is no data record in it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants