Tag: 数据库

如何在对话中显示两种不同模式之间的关系

问题是我有两个不同的Schema可以代替Conversation模型中的用户属性,我怎么能代表这个。 它可能是Student谁messaged或User发送消息,请注意学生和用户是不同的模型/架构。 var mongoose = require('mongoose'); var schema = mongoose.Schema({ message: { type: String, required: true }, user: { type: ObjectId, ref: 'User' /* I want a Student to also be a ref */ } }, { timestamps: true }); var model = mongoose.model('Conversation', schema); module.exports = { model, schema }; 我该如何更好地表示或编写此架构/模型?

正确的postgresSQL查询node.js

我使用node.js服务器和PostgresSQL数据库尝试创build一个提醒应用程序。 我将有关提醒的数据插入到数据库中,然后尝试检查date是否正确,以将提醒推送给用户。 我的解决scheme如果datetime是正确的: 我的问题是:什么是正确的方法来检查date时间是否正确? 也许有一些这样的subsciption? 或任何其他解决scheme呢? 请帮帮我,请提前致谢,欢迎任何帮助!

单个或多个连接到MongoDB更好?

我正在通过Express构build我的Node.js应用程序。 我有两个select来编写代码,以连接到我的MongoDB。 首先是每次执行查询时打开一个连接 https://codeshare.io/a3AQXg 其次是启动应用程序时创build一个单一的连接 https://codeshare.io/GkmR14 然后 function productRepository(db) { this.db = db; }; productRepository.prototype.insert = function(item) { return new Promise((resolve, reject) => { this.db.collection('product').insertOne(item, function(err, result) { if (err) { reject(err); } else { resolve(result); } }); }); }; module.exports = productRepository; 和 module.exports = function(app, db) { var productRepository = require('../model/product'); var productRepoInstance […]

使用Cloud Spanner从数据库中删除logging

在Cloud Spanner文档中的Node.js示例中,我学习了如何从Cloud Spanner数据库查询,读取,插入和更新logging。 但是我不知道如何“删除”logging。 由于插入和更新方法只是'tablename.insert(…)'和'tablename.update(…)',我试过'tablename.delete(…)',但它删除了表本身。 我想删除logging…好像DML语句在查询中不起作用。 如何使用Google Cloud Spanner从数据库中删除logging?

无法从MongoDB数据库获取数据的Web应用程序

我是使用MongoDB的新手。 目前,我正在制作一个需要一些数据存储的Web应用程序。 我在本地主机:3000上运行的Node.js上build立了一个HTTP服务器。 我还使用Vagrant和VirtualBox构build了一个虚拟开发环境。 我正在从PuTTy访问Mongo shell(如果这是相关的)。 在合并MongoDB之前,它正常工作,因为我在Node.js程序内存中存储数据。 这个networking应用程序是一个在线待办事项列表。 我得到的第一个错误是获取路线。 我已经插入Mongo数据库的“待办事项”列表不会出现在本地主机的网站上。 它似乎没有从数据库中获取数据。 我得到的第二个错误是邮政路线。 当我通过本地主机上的用户界面插入“待办事项”并刷新页面时,本地主机上的待办事项列表将更新为特定的待办事项(但不包括我插入数据库中的待办事项)。 但是,它似乎没有将其添加到数据库中,我仍然在控制台上得到这个错误: vagrant@precise32:~/app$ node server.js { description: 'descTest3', tags: [ 'tagTest3' ] } Mongoose: mpromise (mongoose's default promise library) is deprecated, plug in your own promise library instead: http://mongoosejs.com/docs/promises.html 我不知道为什么我得到这个错误,因为我似乎没有使用任何承诺。 server.js var express = require("express"), http = require("http"), app = express(), mongoose = […]

很多很多自我参考在sequelize在twitter像web应用程序

我试图build立一个博客networking应用程序作为练习,特别是了解ORM和Sequelize。 我很容易pipe理post和评论以及用户和post之间的关系。 那里没有问题。 当我尝试将用户作为关注者和用户关联到用户时,恐怖就开始了。 我也希望它有可能跟随你自己。 我曾尝试过这样的事情: const User = sequelize.define('user', { firstName: { type: Sequelize.STRING }, lastName: { type: Sequelize.STRING }, email: { type: Sequelize.STRING }, password: { type: Sequelize.STRING }, activated: { type: Sequelize.BOOLEAN } }) User.belongsToMany(User, {as: "Follower", foreignKey: "FollowerId", through: "Follower_Followeds"}) User.belongsToMany(User, {as: "Followed", foreignKey: "FollowedId", through: "Follower_Followeds"}) 并设置关系: app.post("/followhandler", function(req, res) […]

如何在RethinkDb中使用getNearest函数?

我有一个有关rethinkdb的问题。 我正在查询获得最近的位置周围的一个特定的点和它的罚款,但问题是,要先筛选结果,然后应用getNearest但getNearest与表可以任何人指导我在这里 这里是代码,它工作正常。 但我想先过滤的结果,然后使用GetNearest位置。 var point = r.point(73.07328600000005,33.633473); r.db('DB').table('infoCenter').getNearest(point, {index: 'location', unit: 'km', maxDist:1, maxResults: 2000} ) .filter(function(kk) { return kk('doc')('Deleted').default(false).eq(false) }) 上面的代码工作正常但是我想要做的是先筛选结果,然后使用getNearest方法。 而getNearest方法只能和table一起工作。 提前致谢

webpack只捆绑firebase /数据库而不是firebase / auth

我正在使用我的反应app中的firebase。 我只使用firebase/app和firebase/database模块,所以我只想webpack捆绑我所用的。 但是,webpack捆绑了firebase模块中的所有内容。 我不知道如何告诉webpack忽略其他模块。 我以为我的问题是 import * as firebase from 'firebase'; 不过,我试图只导入一些firebase的东西。 import firebase from 'firebase/app'; import firebase from 'firebase/database'; 但是,webpack仍然捆绑auth.js和其他未使用的模块。 这是我的webpackconfiguration文件。 const path = require('path'); const webpack = require('webpack'); const LodashModuleReplacementPlugin = require('lodash-webpack-plugin'); const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin; module.exports = { cache: true, entry: { main: "./src/swap.tsx", vendor: [ 'babel-polyfill', 'events', 'fbemitter', 'flux', 'react', 'react-dom' […]

在nodejs中远程连接mysql数据库

我想连接另一个服务器数据库。 例如代码是在ABC服务器,我想另一个服务器是XYZ服务器的数据库。 我已经做了。 但得到错误 错误:ER_BAD_DB_ERROR:未知数据库'cp' 在那里我有一个数据库作为CP 交互的服务器代码是 var db_config={ "domain" : "http://****/", "hostname" : "****", "port" : 3306, "user" : "*****", "password" : "****", "database" : "cp" } var connection=mysql.createConnection(db_config); connection.connect(function(err,s){ if (err){ console.log("Error"+err); } else{ console.log("db connected"); } }); 当我删除数据库和凭据是正确的,我可以连接服务器。 如果我使用information_schema作为数据库的名称也db连接正确。 但是当我使用其他数据库我仍然面临着错误 错误:ER_BAD_DB_ERROR:未知数据库'cp' 我已经做了远程访问设置在特定的服务器和检查在PHP代码,其在那里工作很好。 请帮助忙碌的工作。

如何在nodejs中编写数据库模块

在我的项目中,我正在使用MySQL数据库。 问题是,我不知道如何写简单的数据库模块到一个js文件。 我的代码是: 文件:database.js var mysql = require("mysql"); var connection = mysql.createConnection({ host: "localhost", user: "root", password: "", database: "mydb" }); module.exports = class Database { constructor() { connection.connect(function (err) { if (err) { console.error(err); throw err; } else { console.log("Connection to database was successful"); } }); } getConnection() { return connection; } }; 我在项目中有很多文件,每一个都需要使用数据库,问题是,当我每次调用database.js构造函数的时候,我认为它是一个坏的方法。 […]