nodejs + documentdb预热错误

时间:2016-01-30 16:50:29

标签: node.js express azure-cosmosdb

我一直在尝试将DocumentDb支持添加到我的node.js Express应用程序中,如此处所述[{3}}

现在,如果用户在应用程序启动后立即发出请求,则会收到错误,因为我认为我的DocumentDb数据库还没有准备就绪。

我想要的是让我的用户在数据库初始化完成时等待...我怎样才能实现这一点或者node.js中的一般方法来处理在应用程序期间取代的初始化#s; s开始?

var express = require('express');
....

var DocumentDBClient = require('documentdb').DocumentClient;
var config = require('./config');
var StoryDao = require('./models/storyDao');
var Home = require('./controllers/home');

var docDbClient = new DocumentDBClient(config.endPoint, {
    masterKey: config.authKey
});

var storyDao = new StoryDao(docDbClient, config.databaseId, config.storyCollectionId);
var home = new Home(storyDao);
storyDao.init();
....
app.listen(app.get('port'), function(){
    console.log('app started on http://localhost:' + app.get('port') + '; press Ctrl-C to terminate.');
});

1 个答案:

答案 0 :(得分:0)

Standing up a DocumentDB account is a one-time setup and should only take <5 minutes. The easiest thing to do is wait for it to finish.

Otherwise, you could set up a mock DAO... which would be useful from a unit testing perspective :)