为数组的每个元素发出查询

我目前正在查询我的mondo数据库在一个集合中返回一个数组的URL的数组。 然后,我想使用该数组来通过另一个集合,并find前一个查询的返回数组中的每个元素的匹配元素。 在数组上使用forEach并进行个别查询是否正确? 我的代码看起来像这样,第一个函数getUrls很好。 目前我得到的错误是: (节点:10754)UnhandledPromiseRejectionWarning:未处理的承诺拒绝(拒绝ID:1):TypeError:无法读取未定义的属性“限制”(节点:10754)[DEP0018]弃用警告:弃用未处理的承诺拒绝。 将来,未处理的承诺拒绝将使用非零退出代码来终止Node.js进程。 async function useUrls () { let domains = await getUrls() let db = await mongo.connect("mongodb://35.185.206.31:80/lc_data") let results = [] domains.forEach( domain =>{ let query = {"$match": {"email_domain": domain} } let cursor = db.collection('circleback') .aggregate([query], (err, data) =>{ if(err) throw err; console.log("cb", data) }).limit(1100) })

关于Node.js的问题 SChema和模型

关于Node.js的问题 架构,模型和npm。 我是node.js的新手,并按照步骤在mongoose文档中创build模式和模型。 http://mongoosejs.com/docs/ 我正在尝试使用kittens.js输出我在index.js中创build的模型,但我不确定是否正确。 有错误当我尝试编译时, C:\Atom\initial\index.js:11 db.on('error', console.error.bind(console, 'connection_error')); ^ TypeError: Cannot read property 'on' of undefined at Object.<anonymous> (C:\Atom\initial\index.js:11:3) at Module._compile (module.js:570:32) at Object.Module._extensions..js (module.js:579:10) at Module.load (module.js:487:32) at tryModuleLoad (module.js:446:12) at Function.Module._load (module.js:438:3) at Module.runMain (module.js:604:10) at run (bootstrap_node.js:394:7) at startup (bootstrap_node.js:149:9) at bootstrap_node.js:509:3 我在index.js中有以下代码。 var express = require('express'); var mongoose = […]

我的邮政路线有问题吗?

所以我使用一个简单的CRUD风格的网页sequelize。 我的问题是我能够将input的数据input到mysql工作台,它存储在表中,但在网页本身没有任何反应。 //uses var=Posts which contains the fields userName //and userPosts in my database var db = require("../models"); // route to create posts app.post("/api/posts", function(req, res) { console.log(req.body); db.Posts.create({ userName: req.body.username, userPosts: req.body.user_post, }) .then(function(dbPost) { res.redirect('/dashboard'); res.json(dbPost); }); }); 提前感谢任何帮助!

Node.js的帮助,如何发送客户端请求到一个电子邮件?

我一直在努力Node.js,我想要做的一件事是如何发送客户端请求到实际的电子邮件,而不是我的服务器。 例如,我被一个企业聘用,客户端点击“提交”,电子邮件被发送到该企业的电子邮件或他们正在尝试联系。 任何人都知道响应方法是什么? 我似乎无法在网上find任何教程,而Nodemailer教程都是关于从服务器发送电子邮件,这不是我想要做的。

如何在React Native和VSCode中使用带(或不带)Typescript的Nodestream

我使用ReactNativify (而不是更多的hacky的rn-nodeify方法)将一些基于Node的软件包移植到React Native,以在依赖关系树中浏览/ 清除 Node API对象。 我正在开发VSCode。 使用ReactNativify,您可以在.babelrc中使用babel-plugin-rewrite-require (或者在rn-cli.config.js + transformer.js使用javascript): { … "plugins": [ ["rewrite-require", { "aliases": { "constants": "constants-browserify", "crypto": "react-native-crypto", "dns": "node-libs-browser/mock/dns", "domain": "domain-browser", "stream": "stream-browserify", "_stream_duplex": "readable-stream/duplex", "_stream_passthrough": "readable-stream/passthrough", "_stream_readable": "readable-stream/readable", "_stream_transform": "readable-stream/transform", "_stream_writable": "readable-stream/writable", … etcetera } }] … } ( 在这里看一个完整的例子) 这工作得很好,我在VSCode中得到了很好的代码完成/智能感知等。 现在我想在如下的MyStream.js使用Node的Stream: import { Duplex } from 'stream' […]

nodejs npm同时启动错误

我在package.json中有以下代码: "scripts": { "start": "concurrently –kill-others \"npm run _server:run\" \"ng serve –aot –progress=false –proxy-config proxy.conf.json\"", "lint:client": "ng lint", "lint:server": "tslint './server/**/*.ts' -c ./server/tslint.json –fix", "test:client": "ng test", "e2e:client": "ng e2e", "build": "ng build –prod –sm=false –aot –output-path=dist/client && npm run _server:build", "_server:run": "tsc -p ./server && concurrently \"tsc -w -p ./server\" \"nodemon –debug dist/server/bin/www.js\" ", […]

匹配不与Mongoose中的聚合

没有匹配,我得到我需要的输出,当我提供$匹配值,我得到一个空的答复。 什么可能是空回应的原因? 有没有什么不同的方式来调用$匹配参数? var query = {"section":"324444"}; // 324444 is section schema _id value Transaction.aggregate({ "$match": query },{ "$group": { "_id": "$user", "section": { "$first": "$section"}, "amount": { "$sum": { "$cond": ["$credit", "$amount", { "$subtract": [ 0, "$amount" ] }] }} }}) .exec(function(err, transactions) { // Transactions List Grouped User wise }); // Transaction schema […]

只获得协会的协会

我目前正在一个项目中,我有3个模型与儿童和父母的结构。 City有多个Location s有多个Stone s。 每块Stone只有一个Location作为父项,每个Location只有一个City作为父项。 现在,我想创build一个“属于”(通过Location )到特定City的所有Stones列表。 我将如何检索所有这些关联,而不必执行以下操作: City.find({ where: { id: 1337 }, include: [{ model: Location, include: [{ model: Stone }] }] }) .then((city) => { city.stones = [].concat.apply([], city.locations.map(location => location.stones)); }); 我试图找出是否有一个“只有SQL”的解决scheme,所以不检索数据/不得不执行JavaScript来产生这个数组。

续集有许多,属于或两者?

我想正确设置一对一或一对多的关系,事实上,如果我在我的模型定义中使用hasOne / hasMany或belongsTo中的任何一个,似乎都可以正常工作。 例如,以下关联会在其目标上创builduserId字段: User.hasMany(Email, { as: 'emails', foreignKey: 'userId', }) User.hasOne(Profile, { as: 'profile', foreignKey: 'userId', }) 但是几乎在官方文档中的任何地方,我都会看到类似于 Projects.hasMany(Tasks); Tasks.belongsTo(Projects); 即hasMany和belongsTo一起使用。 这是真的需要还是只使用其中一个就足够了? 任何进一步的解释将是非常宝贵的。 谢谢!

我应该caching数据在我的服务器还是只依靠MongoDB

我有一个在Heroku上运行的网站,我使用Mongo Atlas作为我的数据库。 我已经testing了mongo连接速度,根据数据我发现它的大约5ms到20ms注意:Heroku应用程序和Mongo Atlas都在相同的aws区域。 现在我的问题是我有我的用户频繁查询约10Klogging的集合。 对于这个用例,我应该caching这些10Klogging在服务器或者我应该把它留给MongoDB和生活在~15ms的开销? 你怎么看?