草庐IT

node-schedule

全部标签

node.js - 如何在对象中获取一些字段?

我有一个集合“Students”。{student:"JoneDoe",class:"A",subjects:[{subject:"Math",teacher:"Linda","score":"82"},{subject:"English",teacher:"Jone","score":"52"},{subject:"History",teacher:"Maria","score":"32"},]}{student:"BabyDoe",class:"B",subjects:[{subject:"Math",teacher:"Hilary","score":"52"},{subject:

node.js - 如何在模式数组中发布和更新模式并打印它?

你好,我是nodejs和mongoose的新手我有两个方案,我想在另一个方案中有方案对象我的计划用户.js//grabthethingsweneedvarmongoose=require('mongoose');varSchema=mongoose.Schema;varGenre=require('../Models/genre');//createaschemavaruserSchema=newSchema({name:{type:String,required:true,unique:true,index:true},email:{type:String,required:true

node.js - MongoDB 将变量名称更新为键 (Node.JS)

Node.JS、MONGODB,不使用Mongoose。我有一份正在保存的文件。当我使用UPSERT时,它按如下方式构建数据:{"_id":ObjectId("573a123f55e195b227e7a78d"),"document":[{"name":"SomeName"}]}当我使用INSERT时,它会将其全部插入到根级别:{"_id":ObjectId("573a123f55e195b227e7a78d"),"name":"SomeName"}这显然会导致很多不一致。我尝试过各种各样的事情。我尝试了各种方法,例如findOneAndReplace、UpdatewithUpsert

node.js - Mongoose 切片数组,在填充字段中

我有以下mongoose模式:主要的是userSchema,它包含了一组friend,friend架构。每个friendSchema都是一个包含messageSchema数组的对象。messageSchema是最深的对象,包含消息的主体。varmessageSchema=newmongoose.Schema({...body:String});varconversationsSchema=newmongoose.Schema({...messages:[messageSchema]});varfriendSchema=newmongoose.Schema({user:{type:mon

node.js - Mongoose 在字段组合上找到

是否可以使用mongoose搜索两个字段的串联。来自Mysql的类似内容:select*fromCARSwhereconcat(make,model)="";比如说,我有如下的汽车模式:varcarSchema=newmongoose.Schema({model:String,make:String,});varCar=mongoose.model('Car',carSchema);现在有以下可能:Car.find({make+model:},function(err,car){}); 最佳答案 您需要使用aggregate()方法

node.js - 无法发布(评论帖子)| Mongodb 与 Mongoose

我正在结合Mongodb使用NodeJS/Express构建一个应用程序,我希望能够在其中对帖子发表评论,但我一直收到404notfound。我在server.js中设置了模型和路由,还在两者之间设置了“ref”,但这是我不断收到的响应:正如您在下面看到的,“捕获”又名“发布”确实存在:编辑:根据Zen给我的答案对我的初始代码进行了一些更改。这是我的代码:-server.js//InitExpressWebFrameworkvarexpress=require('express');varapp=express();varpath=require('path');//Setviewen

node.js - 使用 Mongoose 进行架构投票的 "right way"?

我正在使用Mongoose/MongoDB创建一个网络应用程序来存储将要投票的信息。我将在投票时存储用户名和IP地址(这样选民可以根据需要更新/修改他们的投票)。根本问题:在Mongoose架构中安全架构投票的最佳方式是什么?目前,我的模式看起来像这样(简化):varThing=newSchema({title:{type:String},creator:{type:String},options:[{description:{type:String},votes:[{username:{type:String},ip:{type:String}}]}]});mongoose.mode

node.js - db.collection.insert 与 db.collection.insertOne 和 db.collection.insertMany 的性能影响

我正在为NodeJs使用mongodb驱动程序,其中有3个方法:1)db.collection.insert2)数据库.collection.insertOne3)db.collection.insertMany我发现db.collection.insert完成了insertOne和insertMany的工作。我也找到了相同的删除和更新方法。相对于db.collection.insertOne和db.collection.insertMany方法,调用db.collection.insert方法对性能有影响吗?可以安全地假设我在某个时间点将拥有数百万条记录的集合中工作。

node.js - MongoError 未知组运算符

我正在为NodeJS使用MongoDb驱动程序。我在使用聚合时遇到问题。错误是{"name":"MongoError","message":"unknowngroupoperator'_id'","ok":0,"errmsg":"unknowngroupoperator'_id'","code":15952}对于下面的脚本:MongoClient.connect(url,function(err,db){if(err){console.log('UnabletoconnecttothemongoDBserver.Error:',err);return;}varcollName="ord

node.js - Mongoose 查询,选择 10 个最近的文档而不改变顺序

我需要从我的消息集合中选择10条最近的消息,并将它们作为数组从旧到最新返回。示例:m1,m2,m3,...[m19,m20,m22]slice运算符很棒,因为它可以取-10这样的值,因此可以从数组中选择最后10个值。问题是我想对整个查询响应进行排序,而不是响应中的属性(slice运算符有2个参数,第一个是path)。其实我做的是:.find({conversation:conversationId}).sort('-updatedAt').limit(10).exec(function(err,messages){});但它返回的数组包含从最近到较旧的消息。我该怎么做才能保持良好的秩序