使用mongodb

时间:2019-05-18 17:12:36

标签: mongodb ubuntu digital-ocean keystonejs

因此,按照https://www.digitalocean.com/community/tutorials/how-to-install-and-secure-mongodb-on-ubuntu-16-04上的文章

我添加了一个用户,并将安全性更改为on(我没有mongod.conf文件,但我有具有不同设置的mongodb.conf文件)

我在ubuntu数字海洋飞沫上使用keystonejs。

此刻我的keystonejs应用看起来像这样

password = process.env.DB_PASS
passworddev = process.env.DB_PASS_DEV

keystone.set("mongo","mongodb://admingreg:"+password+"@127.0.0.1:27017/admin")
// keystone.set("mongo","mongodb://:test1"+passworddev+"@localhost:27017/my-site")



    keystone.set('cloudinary config', process.env.CLOUDINARY_URL);
    keystone.set('cookie secret', process.env.COOKIE_SECRET);

    keystone.import('models');


    keystone.set('locals', {
        _: require('lodash'),
        env: keystone.get('env'),
        utils: keystone.utils,
        editable: keystone.content.editable,
    });
    keystone.set('routes', require('./routes'));
    keystone.set('adminui custom styles', './public/styles/keystone.less');
    keystone.set('nav', {
        posts: ['posts', 'post-categories'],
        galleries: ['galleries','mag','ophelia'],
        images:'images',
        enquiries: 'enquiries',
        users: 'users',
        pages:['ExtraPage','HomePage','AboutPage','ArtistPage','ContactPage','Blog_Page', 'ExhibitionPage'],
        exhibitions:['Exhibition', 'ExhibitionCategory']
    });

    keystone.set('cloudinary secure', true);



keystone.init({
    'name': 'My Site',
    'brand': 'My Site',
    'port':'3000',
    'less': 'public',
    'static': 'public',
    'favicon': 'public/favicon.ico',
    'views': 'templates/views',
    'view engine': '.hbs',


    'custom engine': ephbs.create({
        layoutsDir: 'templates/views/layouts',
        partialsDir: 'templates/views/partials',
        defaultLayout: 'default',
        helpers: new require('./templates/views/helpers')(),
        extname: '.hbs',
    }).engine,

    'auto update': true,
    'session': true,
    'auth': true,
    'user model': 'User',
});

我的conf文件中的重要更改

bind_ip = 127.0.0.1
#port = 27017

# Turn on/off security.  Off is currently the default

#noauth = true
auth = true

我可以使所有内容都可以在同一个Keystone应用程序的本地实例上运行,但是由于某些原因,在实时版本上会出现以下错误

0|keystone |   name: 'MongoError',
0|keystone |   message: 'auth failed',
0|keystone |   ok: 0,
0|keystone |   errmsg: 'auth failed',
0|keystone |   code: 18 }

这很奇怪,因为我创建了一个用户“ admingreg”,并且在管理数据库中将密码设置为“ test”,并且我还尝试更改mongo字符串以匹配数据库“ my”中的一个梯形失真用户-site”,因为它用于开发字符串。 我已经用console.log记录了process.env的设置,它是正确的,所以问题与液滴上的mongodb的设置有关

mongodb错误日志

2019-05-17T23:43:40.423+0000 [conn84] assertion 13 not authorized for query on my-site.system.indexes ns:my-site.system.indexes query:{ ns: "my-site.artists" }
2019-05-17T23:43:40.423+0000 [conn84]  ntoskip:0 ntoreturn:1000
2019-05-17T23:43:40.423+0000 [conn84] assertion 13 not authorized for query on my-site.system.indexes ns:my-site.system.indexes query:{ ns: "my-site.exhibitions" }
2019-05-17T23:43:40.423+0000 [conn84]  ntoskip:0 ntoreturn:1000
2019-05-17T23:43:40.424+0000 [conn84] assertion 13 not authorized for query on my-site.system.indexes ns:my-site.system.indexes query:{ ns: "my-site.exhibitioncategories" }
2019-05-17T23:43:40.424+0000 [conn84]  ntoskip:0 ntoreturn:1000
2019-05-17T23:43:40.424+0000 [conn84] assertion 13 not authorized for query on my-site.system.indexes ns:my-site.system.indexes query:{ ns: "my-site.galleries" }
2019-05-17T23:43:40.424+0000 [conn84]  ntoskip:0 ntoreturn:1000
2019-05-17T23:43:40.424+0000 [conn84] assertion 13 not authorized for query on my-site.system.indexes ns:my-site.system.indexes query:{ ns: "my-site.images" }
2019-05-17T23:43:40.424+0000 [conn84]  ntoskip:0 ntoreturn:1000

0 个答案:

没有答案