js + sequelize使用JSON插入280K行数据.JSON是一个280K的数组.有没有办法在块中进行批量插入.我发现更新数据需要花费大量时间.当我试图将数据减少到40K行时,它可以快速工作.我采取了正确的方法.请指教.我使用postgresql作为后端.
PNs.bulkCreate(JSON_Small)
.catch(function(err) {
console.log('Error ' + err);
})
.finally(function(err) {
console.log('FINISHED + ' \n +++++++ \n');
});
Run Code Online (Sandbox Code Playgroud) 我正在为猫鼬编写一个中间件,它使用预查询钩子为每个查找对象执行。
postSchema.pre('query', function(query, next) {
// I want to access the req.user object here
query.populate('Category');
next();
});
Run Code Online (Sandbox Code Playgroud)
我想为每个向 api 服务器发出的请求访问 pre 中的 req.user 对象。如何将对象传递给中间件?
甚至有可能吗?
https://github.com/Automattic/mongoose/issues/1931
我找到了上面的但它没有谈论传递 req 对象。
====================
在对这个问题有些困惑后进行编辑。
我想要完成的是获取 req.user 角色和模型名称将其传递给另一个函数以获取查找的查询条件。因此,根据用户角色和访问的模型类型,查询条件会发生变化。
我正在尝试找到一种方法来修改猫鼬的查询结果。
下面是带柱钩的独立模型
'use strict';
// load the things we need
var mongoose = require('mongoose');
var invoice_db = mongoose.createConnection(config.mongo.url + '/invoiceDB'); //connect to buyer DB
var path = require('path');
// define the schema for our invoice details model
var invoicedetailSchema = new Schema({
//SCHEMA INFO
});
invoicedetailSchema.post('find', function(results){
console.log('POST FIRED')
results = results.filter(function(doc){
return doc.tags.length;
})
})
var InvoiceModel = invoice_db.model('InvoiceDetail', invoicedetailSchema);
// create the model for seller and expose it to our app
promise.promisifyAll(InvoiceModel);
promise.promisifyAll(InvoiceModel.prototype);
module.exports = InvoiceModel;
Run Code Online (Sandbox Code Playgroud)
查找查询工作正常并且帖子正在触发,但结果没有根据帖子挂钩进行过滤。
在返回结果之前我该如何编辑结果。
嗨,我有以下格式的数据框。
为简单起见,我展示了按年份分类的数据,但它有季度数据。我想做一个线图,最小最大值作为阴影,平均值作为线图。我尝试了不同的方法来做到这一点,但我无法在我需要的输出中得到它,如下所示。
作为替代方案,带有均值、最小值和最大值的箱线图也可以使用。
需要的输出
node.js ×3
mongodb ×2
mongoose ×2
javascript ×1
json ×1
matplotlib ×1
pandas ×1
plot ×1
postgresql ×1
python ×1
sequelize.js ×1