环回 automigrate /自动更新模型到mongodb

新的loopback和和我不能为我的生活迁移一个单一的json模型到我的mongodb数据源。

我一直在忙着: https : //docs.strongloop.com/display/public/LB/Creating+a+database+schema+from+models

以下是我迄今为止所尝试的:

我创build了一个迁移脚本bin/migrate.js ,我计划在每次需要使用自动更新来迁移更改时运行它们:

 var path = require('path'); var app = require(path.resolve(__dirname, '../server/server')); var ds = app.datasources.acme; var appModels = ['Client']; ds.isActual(appModels, function(err, actual) { if (!actual) { ds.autoupdate(appModels, function(err) { if (err){ throw (err); } }); } }); console.log("Migrated: " + appModels.join()); 

我使用robomongo和mongo cli检查了两个,我找不到生成的表:

 > use acme switched to db acme > db.getCollectionNames(); [ ] 

我也是mongodb的新手,所以如果我正在检查迁移是否成功,那么可能会出现错误。

我已经在这里尝试了答案,但它不适用于我:将内置模型迁移到数据库

其他一些相关的东西:

datasources.json

 { "acme": { "host": "127.0.0.1", "port": 27017, "database": "acme", "username": "root", "password": "password", "name": "acme", "connector": "mongodb", "user": "root" } } 

我的模特

 { "name": "Client", "plural": "Clients", "base": "User", "idInjection": true, "options": { "validateUpsert": true }, "properties": { "contact_number": { "type": "string" } }, "validations": [], "relations": {}, "acls": [], "methods": {} } 

原来,这实际上是工作。 来自一个mysql背景,我不知道你只能看到一个mongodb集合里面有文档。

当我添加以下内容时,我得到了正在查找的视觉确认:

 app.models.Client.create([ {contact_number: '09xxxxxxx', password: 'password', email: 'acme@gmail.com'}, ], function(err, clients) { if (err){ throw err; } console.log('Models created: \n', clients); });