草庐IT

Node-red

全部标签

node.js - 当我创建一个带有引用另一个 Mongoose 对象的位置的模式时,如何防止 Mongoose 创建 id?

这不是重复问题,因为我“重复”的问题是关于从子化学中删除ID。在这里,我想防止mongoose使用referencenothing的ID填充我日历中的时间。它只是应该存储带有类(class)ID的类(class)。我正在尝试制作一个包含周、日和小时的日历,其中每个小时都应该能够引用一个类(class)。这是我的日历架构:varmongoose=require("mongoose");varcalendarSchema=newmongoose.Schema({owner:{type:mongoose.Schema.Types.ObjectId,ref:"User"},weeks:[{nu

node.js - 类型 'x' 上不存在 Mongoose 属性 'Document'

ts编译器说“文档”类型上不存在任何属性。似乎正因为如此,模型上的所有属性都无法设置。如果我将用户对象打印到控制台,我得到的只是{"_id":"长十六进制ID号"}我的模型配置如下:用户.tsimport*asmongoosefrom'mongoose';import*ascryptofrom'crypto';import*asjwtfrom'jsonwebtoken';varuserSchema=newmongoose.Schema({email:{type:String,unique:true,required:true},firstMidname:{type:String,req

node.js - 一旦保存在 Mongoose 中,如何使某些字段不可更新?

我已经构建了一个架构如下:constUserInfoSchema=newSchema({email:{type:String,required:true,unique:true},username:{type:String,required:true,unique:true},userId:{type:Schema.Types.ObjectId,ref:'User'},displayName:{type:String,required:true},profilePic:{filename:{type:String},url:{type:String}},created_at:Date,

Node.js 使用聚合查找调用 MongoDB

我用了很长时间的SQLServer,刚刚真正学习了MongoDB。我想弄清楚如何进行聚合查找以获取我想要的数据。这是数据库中的示例:{"_id":"1","user_id":"123-88","department_id":"1","type":"start","time":"2017-04-20T19:40:15.329Z"}{"_id":"2","user_id":"123-88","department_id":"1","type":"stop","time":"2017-04-20T19:47:15.329Z"}我想做的是找到部门1的每个唯一user_id,只取最晚时间的记录并

node.js - 如何访问预更新 Mongoose 中间件中的文档对象?

考虑一下,我有一个像这样的Mongoose模式constmySchema=newmongoose.schema({val1:Number,val2:Numberval_1_isBigger:Boolean})现在我想在每次更新操作之前比较val1和val2,因此我想为val_1_isBigger设置bool属性。我的问题是如何在pre('update')mongoose插件操作期间访问文档对象。看下面的例子mySChema.plugin(function(schema,options){schema.pre('update',function(next){//HereHowDoIcom

node.js - Mongo/Mongoose 聚合 - $redact 和 $cond 问题

我很幸运能够得到另一个SO问题的精彩答案Mongo/Mongoose-AggregatingbyDate来自@chridam,它给出了一组文档,例如:{"_id":ObjectId("5907a5850b459d4fdcdf49ac"),"amount":-33.3,"name":"RINGGO","method":"VIS","date":ISODate("2017-04-26T23:00:00Z"),"importDate":ISODate("2017-05-01T21:15:49.581Z"),"category":"NotSet","__v":0}{"_id":ObjectId

node.js - 当 cron 在后台运行时,没有 Mongo 查询得到结果

我一直将NodeJS作为服务器端,将MongoDB作为我们的数据库。它真的很适合一起使用。现在我已将node-schedule库添加到我们的系统中,以调用像cron-job一样的函数。该过程大约需要数小时才能完成。我的问题是每当cron运行时,我站点的所有用户都得不到服务器的响应,即数据库被锁定。坚持了一周的问题,需要好的解决方案来运行cron,而不影响用户使用该网站。 最佳答案 通常,您会希望编写一个worker并在不属于您的服务器的不同入口点运行该worker。您可以通过多种方式实现这一目标。1)在另一台服务器上编写一个work

node.js - node-mongodb 防止 websocket 数据丢失

我在使用SocketCluster的websocketAPI的客户端用于其发布/订阅。验证后,我通过接收每秒的json数据SCsocket.on('authenticate',function(){varchannel=SCsocket.subscribe('channel1');channel.watch(function(data){console.log(data);});});形式[{"product":"Product1","price":"10.0"},{"product":"Product2","price":"15.0"}]我不会打印数据,而是将其保存到mongo数据库

node.js - 在 Express : userid not found 中使用 rest api

灵感来自GettinMEAN我正在制作自己的应用程序。我尝试在Express中将前端连接到后端。我复制了文本,但我的console.log仍然给我消息“未找到用户ID”。我想我已经很接近完成了。感谢任何提示或有用的链接。用户模型constuserSchema=newSchema({firstName:String,lastName:String,userName:String,telephone:String,password:String});2.api中的路由router.route('/users/:userid').get(ctrlUsers.userReadOne);modu

node.js - MongoDB 连接在测试场景中不会关闭

我正在使用express并通过npm包"mongodb":"^3.0.10"连接到mongodb。我的app.ts看起来像这样:constapp=express();letserver:http.Server;(async()=>{app.use(bodyParser.json());letdb:Db;try{consthost=config.get("api.dbConfig.host");console.log(host);constdbName=config.get("api.dbConfig.dbName");constport=config.get("api.dbConfig