草庐IT

Node-red

全部标签

node.js - Mongoose 从数组元素中选择特定字段

假设我有这个模式{jedi:[{name:Stringlightsaber_color:String]}}我想返回全部并且只返回他们的名字。我试过了Jedi.find({}).select('jedi.name').exec(function(err,jedi){if(err){console.log("nothingfound")}}它什么都不返回,而这段代码返回所有内容。Jedi.find({}).select('jedi').exec(function(err,jedi){if(err){console.log("nothingfound")}}我看到jedi是一个数组,所以我认

node.js - 设置 Heroku Scheduler 作业以向所有用户发送电子邮件 (Meteor/MongoDB)

有谁知道是否可以制作一个每天向我的所有用户发送一封电子邮件的HerokuScheduler作业?我正在使用Meteor和MongoDB。我可以看到HerokuScheduler可以运行诸如“nodesomefile.js”之类的命令,但我似乎无法弄清楚如何在这样的文件中连接到mongodb。我可以在不涉及Meteor的情况下以某种方式利用数据库吗?如有任何帮助,我们将不胜感激! 最佳答案 我最终找到了一个包:synced-cron.基本上,您需要设置一种使用包来触发重复作业的方法。包网站也有示例代码:SyncedCron.add({

node.js - MongoDB 使用 Mongoose 保存问题

我在使用Mongoose在我的mongodb中保存数据时遇到了一些问题。这是我使用的代码:////////////////////////////////////////////Mongoosetestvarurl=mongoUrl+dbCollectionName;varmongoose=require('mongoose');mongoose.connect(url);vardb=mongoose.connection;db.on('error',console.error.bind(console,'connectionerror:'));db.once('open',funct

node.js - Mongoose 通过id方法删除子文档

我有两个模型:varmongoose=require('mongoose');varSchema=mongoose.Schema;varProjectSchema=newSchema({title:{type:String},images:[{type:Schema.Types.ObjectId,ref:'Image'}]});module.exports=mongoose.model('Project',ProjectSchema);和varmongoose=require('mongoose');varSchema=mongoose.Schema;varImageSchema=ne

node.js - 如何从父实例访问 Mongoose 中的子文档实例?

varmongoose=require('mongoose');varSchema=mongoose.Schema;varChildSchema=newSchema({name:String});ChildSchema.methods.getName=function(){returnthis.name;}varParentSchema=newSchema({children:{type:[ChildSchema]default:[]}});ParentSchema.methods.getChildName=function(){//Howtofacilitateabilitytoac

node.js - 为什么不能修改 Mongoose 查询返回的数据(例如 : findById)

当我尝试更改Mongoose查询返回的数据的任何部分时,它没有任何效果。我昨天花了大约2个小时试图解决这个问题,使用各种_.clone(),使用临时存储变量等。最后,就在我想我要去的时候疯了,我找到了解决办法。所以我想将来有人(fyuuuuture!)可能会遇到保存问题。Survey.findById(req.params.id,function(err,data){varlen=data.survey_questions.length;varcounter=0;_.each(data.survey_questions,function(sq){Question.findById(sq

node.js - 在 mongo 中保存时,Mongoose 纬度和经度验证不起作用?

以下是我的位置收集架构:varLocationSchema=newSchema({street:{type:String,required:true},area:{type:String,required:true},city:{type:String,required:true},state:{type:String,required:true},zip:{type:String,required:true},country:{type:String,default:'IN'},pointers:{type:[],index:'2dsphere'}});当使用mongoose指针在m

node.js - 如何使用 $lookup 和 DbRef 连接 MongoDB 和 NodeJS 中的两个集合?

如果我有两个集合,其中一个有dbref,如何使用$lookup和dbref加入? 最佳答案 DBref是一个BSON对象,您不能使用它的值进行查找。但是,有一种方法可以将DBRef对象转换为数组。Ihavewrittenananswerafewmonthsagodescribinghowtodoit.简短说明假设您有这样的DBRef对象:myField:DBRef("otherCollection",ObjectId("582abcd85d2dfa67f44127e0")),像这样在myField上使用$objectToArrayd

node.js - 使用 mongoose 将 node.js 连接到 MongoDB 中的分片副本集群的正确方法

最近我们重新设计了我们的MongoDB数据库集群,除了我们已经实现的分片之外,还使用了SSL和副本集。SSL工作起来并不难,我们只需要拆分私钥和证书,然后一切正常。然而,事实证明,让我的Node.js应用程序连接到两个mongos实例比我预期的要困难。在我们实现副本集之前,我们只有两个分片,每个分片都运行一个mongos路由器,在mongoose中我给它以下连接字符串:mongodb://Host1:27017,Host2:27017/DatabaseName然后,在连接的选项对象中,我传入了以下内容:{mongos:true}这似乎工作得很好。但是,在实现副本集后,每当我通过mong

node.js - 无法访问 Typescript 中的 mongoose Schema 上下文

我正在尝试将.pre、.method和.static函数应用于我的Mongoose模式。我有以下代码,但我的this要么在错误的上下文中,要么我误解了Schemas。exportinterfaceIUserextendsmongoose.Document{email:string;password:string;firstName:string;lastName:string;comparePassword(password:string,callback:Function):void;}classUserSchema{staticgetschema():mongoose.Schema