我在快速服务器上使用 winston-elasticsearch,我只是编写了与文档中相同的代码
var winston = require('winston');
var Elasticsearch = require('winston-elasticsearch');
var esTransportOpts = {
level: 'info'
};
var logger = winston.createLogger({
transports: [
new Elasticsearch(esTransportOpts)
]
});
Run Code Online (Sandbox Code Playgroud)
当我运行服务器时,出现此错误:
类型错误:Elasticsearch 不是构造函数
我已经安装了最新版本“winston”:“^3.2.1”和“winston-elasticsearch”:“^0.8.8”
我正在对一个调用环境变量的函数运行测试,但未定义。我尝试过但不起作用的解决方案:
1/添加require('dotenv').config({path:'../.env'})
到我的测试文件中
2/ 在 package.json 中传递全局变量
"jest": {
"globals": {
"USER_ENDPOINT":"xxx",
"USER_KEY":"xxx"
}
}
Run Code Online (Sandbox Code Playgroud)
3/在package.json中的测试命令中传递我的变量
"test": "USER_ENDPOINT:xxx USER_KEY:xxx jest --watchAll --detectOpenHandles"
Run Code Online (Sandbox Code Playgroud)
4/ 在我的测试文件中的 beforeEach() 中添加了一个 Object.assign
beforeEach(() => {
process.env = Object.assign(process.env, {USER_ENDPOINT:"xxx", USER_KEY:"xxx" });
});
Run Code Online (Sandbox Code Playgroud)
并收到错误“Jest 遇到意外令牌”
5/我在根目录下创建了一个 jest.config.js 文件
require('dotenv').config({path:'./.env'});
module.exports = {
globals: {
USER_ENDPOINT:"xxx",
USER_KEY:"xxx"
}
};
Run Code Online (Sandbox Code Playgroud)
大多数这些解决方案都在这里建议: https: //github.com/vuejs/vue-test-utils/issues/193 ,但都不起作用
我有一个类似的 mongodb 集合:
{ "_id" : 1, "item" : "item1", "quantity" : 2, "date" : ISODate("2014-01-01T08:00:00Z") }
{ "_id" : 2, "item" : "item2", "quantity" : 1, "date" : ISODate("2014-02-03T09:00:00Z") }
{ "_id" : 3, "item" : "item2", "quantity" : 5, "date" : ISODate("2014-02-03T09:05:00Z") }
{ "_id" : 4, "item" : "item1", "quantity" : 10, "date" : ISODate("2014-02-15T08:00:00Z") }
{ "_id" : 5, "item" : "item2", "quantity" : 10, "date" : ISODate("2014-02-15T09:05:00Z") }
Run Code Online (Sandbox Code Playgroud)
我想获取每个项目的最新文档(基于日期值)
意味着我想要一个查询/聚合给我:
{ …
Run Code Online (Sandbox Code Playgroud)