草庐IT

node-keyboard

全部标签

node.js 为什么剂量 mongodb 抛出类型转换错误

//thiserrorappear{"error":{"message":"CasttoObjectIdfailedforvalue\"events\"atpath\"_id\"formodel\"user\"","name":"CastError","stringValue":"\"events\"","kind":"ObjectId","value":"events","path":"_id"}}//whenexecutethiscodeexports.get_all_events=(req,res,next)=>{Event.find({}).populate("creator"

node.js - 使用对象作为在 router.get 中查找值的键

我正在使用这个Controller来使用我的服务然后调用我的router.get,我想在从mongodb获取请求时使用userObject.blood_component作为searchFinderController:varuserObject={};userObject.blood_component="findme";Bloodstock.getStocks(userObject).then(function(data){});然后调用api路由:服务:bloodstockFactory.getStocks=function(userObject){return$http.get

node.js - 我可以使用 MongoDB 模式模型来定义 IndexedDB 索引吗?

我正在创建一个渐进式网络应用程序,它使用NodeJS和Express作为后端,使用MongoDB作为服务器,使用IndexedDB在离线时在本地存储数据。目前我已经定义了一些Mongoose模式模型,我的应用程序假设从我的MongoDB服务器获取数据并在应用程序上线时将其存储到我的本地IndexedDB中。是否可以让我的IndexedDB的索引遵循我的Mongoose模式模型的格式,这样如果我对模型进行了一些更改,IndexedDB的索引也会遵循这些更改。 最佳答案 问题不是很清楚,举个例子会有帮助。但据我了解,您希望能够在不破坏I

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

javascript - 使用 $match 的聚合查询在 MongoDB Compass 中有效,但在我的 Node.js 应用程序中无效

我有一个Booking模型和一个Event模型。我正在尝试查询并检查是否有任何预订已经具有特定的Event._id和User._id,以停止创建重复的预订该用户和事件。聚合查询适用于MongoDB罗盘,但是当我在Node.js应用程序中尝试查询时它只给我一个空数组模型预订constBookingSchema=newSchema({amount:{type:Number,required:'Pleasesupplyanumberofpeople',},event:{type:mongoose.Schema.ObjectId,ref:'Event',required:'Mustgivean

javascript - 更新收藏并在满足条件时发送电子邮件 || Mongo Node

这个问题在这里已经有了答案:LoopingResultswithanExternalAPICallandfindOneAndUpdate(1个回答)关闭3年前。我有以下情况-我想遍历db中的每个元素并且:如果元素的bumped字段设置为false并且创建日期小于30天前然后:将bumped设置为true给用户发邮件!我的方法:User.updateMany({bumped:false,creationDate:{$gte:newDate(Date.now()-30*24*60*60*1000),},},{$set:{bumped:true,},},(err,res)=>{////Wha

node.js - 根据条件使用来自不同集合的 $lookup

我有3个收集司机、用户和调度员。调度员可以是司机或用户我的调度员集合是这样的,{"_id":ObjectId("5c9bb56a56f1a43e8aedf3c1"),"dispatcherId":ObjectId("5c3382fe3406281ba6863f7e"),"type":"driver","recordedTime":ISODate("2019-03-27T17:39:54.030Z"),"isEnable":true,"dispatchPackageType":"commission","__v":0}dispatcherId来自驱动程序或用户集合。类型是“驱动程序”或“

node.js - 如何在 MongoDB 的数组字段中投影特定元素?

我在MongoDB中有这些数据:{"_id":ObjectId("5c7e459f875ea5548de25722"),"Autos":[{"_id":ObjectId("5cad9759e1c3895999adaceb"),"deleted":1,},{"_id":ObjectId("5cad9a8be1c3895999adacef"),"deleted":0,},{"_id":ObjectId("5cad9aa4e1c3895999adacf0"),"deleted":0,}]}{"_id":ObjectId("5c7e45e9875ea5548de25724"),"Shoemak

node.js - 如何计算组聚合的评分?

我被困在mongodb聚合上以获得评分。我已经在努力让自己成为管道。看上面数据(产品集合){"status":200,"message":null,"data":{"_id":"5cc570257631a313d489ba4a","media":["httpsdssd","dfdfd"],"comment":["5cc57f1053273c05cc60e707","5cc585bf6ff7a812e0e7d9d9","5cc5c654bc73b408787ffadc","5cc5c6e3bc73b408787ffadd"],"store":"5cc2c9710bc5d615781fcf

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