草庐IT

expressive

全部标签

node.js - Mongoose 和 Express,如何从数据库中获取唯一记录?

在我的数据库中,我有2-3strip有title的记录(第一条)。我怎样才能得到1个结果?以下是我的代码不起作用,app.get('/',(req,res)=>{Article.find.distinct(title,(err,title)=>{if(err){console.log(err);}else{console.log(articles);res.render('index',{title:'Articles',articles:title});}});});但是如果我使用,Article.find({},(err,title)它有效,但我不需要对象,因为它们都是独一无二的我

node.js - Express.js+蒙戈: TypeError: Cannot read property then of undefined

我知道这里还有其他问题询问同样的错误,但我找不到适合我的情况的问题。我尝试连接mongo数据库:vardbConn=MongoClient.connect('mongodb://localhost',function(err,client){if(err)throwerr;vardb=client.db('mytestingdb');});我在这部分代码上遇到错误:app.post('/thanks',function(req,res){if(atendees.checkin===req.body.dbstring){dbConn.then(function(db){//errorhe

mongodb - 处理 CRUD 应用程序中的重复值错误(react-redux + express-mongoose)

具有mongoose架构,其中carNumber应该是唯一的:varSchema=mongoose.Schema({createdAt:{type:Date,default:Date.now},carNumber:{type:String,index:{unique:true,dropDups:true},},carOwner:String});使用expresscontroller函数数据保存到db:exportconstaddCar=(req,res)=>{constnewCar=newCar(req.body);newCar.save((err,car)=>{if(err){re

node.js - Express API REST 过滤数据 MongoDB

我有一个带有express和mongo的PokemonAPIREST。我正在尝试按他的类型过滤口袋妖怪。我从Angular发送一个httpGET,其中包含要过滤参数的类型。有以下controller.jsconstpokemons=require('../models/pokemon');constlaboratoryCtrl={};laboratoryCtrl.filterPokemon=async(req,res)=>{constfilterType=req.query.type;//filterType="Fire"constpokemon=awaitpokemons.find(

javascript - 不能使用 Node js(express) 和 MongoDB(mongoose) 对用户配置文件进行审核

我在为用户添加评论时遇到问题。一旦我为用户创建评论,它只显示id,而不显示文本或作者或任何其他属性。很高兴听到任何想法。这是我的架构和路线:1)用户模式:varmongoose=require("mongoose");varpassportLocalMongoose=require("passport-local-mongoose");//SCHEMASETTINGUPvarUserSchema=newmongoose.Schema({username:String,password:String,isAdmin:{type:Boolean,default:false},firstNa

node.js - Bcrypt 密码比较不起作用。 Node.js Express App 中甚至 user.password 为空

在这里,我正在使用Node.jsExpress应用程序学习MongoDB。我正在使用Bcrypt保护我的密码。在mongodb中加密和保存是成功的,但是当我尝试比较SigIn的密码时,它只是失败了。SignUprouterouter.post('/signUp',(req,res,next)=>{letuserData=req.body;mongoose.connect(DB_URL,{useNewUrlParser:true},(err)=>{if(err)throwerr;console.log('DBisconnectedSuccessfully');bcrypt.hash(us

node.js - 蒙戈/ express : How to return all documents in collection if no query params are passed?

如果没有传递查询参数,我将尝试从我的Mongo集合中返回所有文档。目前我有3个可选的查询参数可以由用户传递。localhost:3000/api/projects//shouldreturnallprojects.Currentlythisisreturning[]localhost:3000/api/projects?id=1//shouldreturnprojectswithidof"1".Workingproperly.localhost:3000/api/projects?name=myproject//shouldreturnprojectswithnameof"myproj

macos - 通过 Express 和 MongoDB 使用 session ,为什么我只能连接一次路由,除非我更改我的 session 密码?

我在Express.js中有一个应用程序,我在端口5000上运行。我已经为此工作了一段时间,一切都很好。不过最近出了点问题,可能与升级到MountainLion有关。我不确定。为了简化应用程序,我现在只设置了一个示例GET路由:app.get('/',function(req,res){console.log('madeithere');res.end('Heythere');});出于某种原因,当我尝试通过网络浏览器(chrome、safari)连接时,它不会连接多次。但是,如果我通过直接远程登录到端口并发出GET/进行连接,我会得到我期望的响应(因为我假设没有session在进行)

node.js - 如何在 mongoose + express 的模式上使用方法

当我尝试从exports.index.post运行user.comparePassword时出现以下错误(见下文)——我粘贴了所有代码以帮助缩小问题范围。UserSchema.pre('save')方法工作正常,但不是./routes/account.js中的方法(我使用的是mongoose3)这是我得到的错误。Caughtexception:[TypeError:Object{username:'test4',email:'test4@test.com',password:'$2a$10$Ix5vCuVYGIU7AmXglmfIxOyYnF6CiPJfw9HLSAGcRDxMJEtt

asp.net-mvc - 将 MongoDB 和 SQL Server Express 与 Asp.net MVC 一起使用

我正在使用Asp.NetMVC4和C#构建一个网站,托管在VPS中。该站点有很多共享评论/回复功能(我需要存储很多评论)。我打算使用MongoDB,因为它是免费的,也非常适合存储博客/评论,但有点犹豫afterIreadthisarticle.所以现在我正在考虑使用MongoDb来存储评论和回复,并使用具有10GB限制的SQLServerExpress版本来存储用户帐户和其他用户配置文件数据。在一个Web应用程序中使用2个这样的不同数据库可以吗?或者是否有任何其他类似于MongoDb的稳定文档数据库我可以使用并且不必使用SQL服务器?RavenDb是一种选择吗?提前致谢!