草庐IT

nodes_alive

全部标签

node.js - 为什么这个 MongoDB 连接在 grunt 脚本中不起作用?

如果我使用Node运行它,它会打印“已连接到数据库”:varMongoClient=require("mongodb").MongoClient;MongoClient.connect("mongodb://localhost/db1",function(err,db){if(err){throwerr;}console.log("ConnectedtoDatabase");db.close();});但是,如果我尝试使用Grunt任务运行它,它什么也不做,而且是静默的。module.exports=function(grunt){returngrunt.registerTask("t

代码速度慢?避免这 19 种常见的 JavaScript 和 Node.js 错误

译者|刘汪洋审校|重楼速度、性能和响应性在Web开发中起着至关重要的作用,尤其是在使用JavaScript和Node.js开发时尤为重要。如果一个网站响应缓慢或界面卡顿,就会让人感到非常业余;如果网站经过精心设计和优化,能够给用户带来丝滑的使用体验,就显得非常专业。打造一个真正高性能的Web应用并非易事,其中潜藏着许多容易忽视的性能陷阱。这些不易被察觉的编程习惯或错误不仅可能降低JavaScript的执行速度,还可能导致代码冗余,进一步降低应用的运行效率。即使你已经压缩了代码并合理地使用了缓存,网站在某些情况下仍然可能运行缓慢。例如,用户界面在滚动或点击按钮时出现明显的卡顿,或页面加载时间过长

node.js - 带有 node-mongo-native GridFS 检测错误的新 Relic

当我NewRelic=require('newrelic');并执行varNewRelic=require('newrelic'),mongo_native=require('mongodb'),Express=require('express'),http=require('http');GridStore=mongo_native.GridStore;process.on('uncaughtException',function(err){console.log('UncaughtException',err);});mongo_native.connect(mongoLabUri

node.js - 用 Mongoose 更新

我需要设置一个嵌套数组的对象,其属性为“default=true”,但我只需要一个具有此属性,其他对象不得具有此属性。例子:{"_id":"xxxxx","name":"Jmae","desktops":[{"_id":"xxxxx","name":"Mike","default":true},{"_id":"xxxxx","name":"Aris"},{"_id":"xxxxx","name":"John"}]}这只设置,但不删除:varfilter={"_id":platformId,"desktops._id":desktopId},updateParams={"$set":{"

node.js - 如何不保存 Mongoose 中的某个字段?

我正在通过Mongoose更新记录,但是当我尝试通过不将字段包含在属性对象中来不包含它时,该字段只是被设置为空。我的模型:vardemo=newSchema({name:String,slug:String,code:String,details:String,scripts:[],css:[],status:{type:String,default:"draft"},lastModifiedDate:{type:Date,default:Date.now},projectId:Schema.ObjectId});我保存的地方:Demo.find({slug:req.params.de

node.js - 你能为 mongoosejs 中的对象设置部分模式吗?

您可以在mongoosejs中为对象设置部分模式吗?假设我有一个person对象,我想验证它是否始终具有first_name和last_name字段。但我也希望允许用户保存他们选择的其他字段。假设我有以下架构:varuserSchema=newmongoose.Schema({first_name:{type:String,required:"firstnamerequired"}last_name:{type:String,required:"lastnamerequired"}})但我希望该应用能够发布:{first_name:"john",last_name:"doe",fiel

node.js - Node ,js - Mongoose - 无法保存地理多边形 - CastError : Cast to number failed

我正在尝试将地理点和地理多边形保存到Mongo。我的点测试通过,但多边形失败:CastError:Casttonumberfailedforvalue"0,0,3,0,3,3,0,3,0,0"atpath"coordinates"我的架构如下:varGeoSchema=newSchema({name:String,coordinates:[Number]});GeoSchema.index({coordinates:'2dsphere'});我成功保存的测试点对象:geoPoint=newGeo({coordinates:[2,2],type:'Point'});无法保存的我的测试多边

node.js - Mongoose 嵌套数组、树和嵌入式文档

我有一个像这样的Mongoose模式:Schema:ItemSchema:SubItemSchema:SubItemTwo//ItemSchemalookslikethis:Item:{SubItem:[SubItemSchema]}SubItemSchemalookslikethis:{field1:String,field2:String,OtherItems:[SubItemTwoSchema]}SubItemTwoSchema是一些字符串字段的平面模式。基本上,我发现使用查询、$set、$inc和$addToSet运算符等来处理SubItemSchema.OtherItems几

node.js - 基于 Node js 的 Portfolio CMS 数据库

我是Node.js的新手,有点卡住了。有一个项目组合CMS突然出现在我的脑海中,实际上很简单Ghost启发了我,您只需下载它就可以使用,但我突然意识到在这种情况下它可能无法使用。据我所知,Ghost使用SQlight。所以我的问题是,该平台将处理自定义页面,因此用户将能够像在Wordpress中一样创建页面,将处理博客文章、图片库和主题。我一直在考虑使用MongoDB,但我有一些疑问。这样人们就可以创建图片库并将其作为短代码(只是告诉)插入到页面中,我的问题是。MongoDB是否支持这种类型的cms?图片库的嵌入式数据是否会在未来造成问题或有任何限制?图库示例Model.Gallery

node.js - 在 compoundjs 初始化期间,如何从 jugglingdb 适配器获取 native mongodb 客户端?

我正在使用compoundjs并使用jugglingdb的mongodb适配器。我一直在检索并重复使用nativemongodbclient在Controller中执行以下操作:vardb=compound.orm._schemas[0].client;这很好用,因为我能够使用mongodb支持的函数,例如.collection(name)和.find()。但是,当我为compoundjs创建初始化程序时,.client是空的,但看起来_schemas[0]不是。例如:module.exports=function(compound){vardb=compound.orm._schem