删除Mac中的云梯配置:
http://hcleon.iteye.com/blog/2177574
mongodb简单学习
MongoDB的内部构造 From 《MongoDB The Definitive Guide》
http://www.cnblogs.com/gpcuster/archive/2010/10/04/1841877.html
MongoDB——通过客户端理解mongoDB体系结构
http://blog.csdn.net/liusong0605/article/details/10611895
MongoDB内存使用原理
http://www.searchdatabase.com.cn/showcontent_51990.htm
日期:mongodb的日期不包含时区。日期对象 new Date(),日期字符串 Date(…)
json仅包含6中数据类型:(null,布尔,数字,字符串,数组,对象)
局限:1)没有日期类型 2)只有一种数字类型,无法区分浮点数和整数,更别说区分32位和64位数字 3)不能表示其他通用类型,比如,正则表达式
BSON:
mongodb和redis设计原理简析
express4.x
Express.js 4.x 新功能
解读express 4.x源码(1)
Express 4.x的特性和3.x的迁移
Express 4.x API
npm常用命令
查询node模块是否存在
1$ npm search indexName设定安装模式(全局模式、当前应用)
1$ npm set global=true查看当前使用的安装模式
1$ npm get global安装Node模块
1$ npm install moduleNames -g 全局安装查看node模块的package.json文件夹
1234567$ npm view moduleNames$ npm view moduleName labelName 要查看package.json文件夹下某个标签的内容```<!--more-->3. 查看当前目录下已安装的node包``` bash$ npm list$ npm list parseable=true 可以目录的形式来展现当前安装的所有node包查看帮助命令
1$ npm help查看包的依赖关系
1$ npm view moudleName dependencies查看包的源文件地址
1$ npm view moduleName repository.url查看包所依赖的Node的版本
1$ npm view moduleName engines查看npm使用的所有文件夹
1$npm help folders用于更改包内容后进行重建
1$ npm rebuild moduleName检查包是否已经过时,此命令会列出所有已经过时的包,可以及时进行包的更新
1$ npm outdated更新node模块
1$ npm update moduleName卸载node模块
1$ npm uninstall moudleNamepackage.json文件结构说明
1$ npm help json发布一个npm包的时候,检验某个包名是否已存在
1$ npm search packageName
Node.js入门学习
Node.js v0.10.18手册&文档 http://nodeapi.ucdok.com/#/api/
Node.js v0.12.0文档 https://nodejs.org/api/
Node.js入门经典系列学习 http://www.myexception.cn/javascript/1702369.html
Node入门 http://www.nodebeginner.org/index-zh-cn.html#handling-post-requests
node.js是首个将异步大规模带到应用层面的平台;但是异步在流程控制中,业务表达并不适合自然语言的线性思维
nodejs适合于数据密集型实时的web程序,DIRT
node中,I/O几乎总是在主事件轮询之外进行,使得服务器可以一直处于高效并且随时能够做出响应的状态,就想NGINX一样
在node 的世界里有两种响应逻辑管理方式:回调和事件监听
- 回调:通常用来定义一次性响应逻辑(数据库查询定义回调函数来处理查询结果)
- 事件监听器:本质也是一个回调,不同的是它跟一个概念实体(事件)相关联。
mongoose查询操作的高级应用
Node.js测试报错
|
|
原因:
|
|
让人纠结的mongoose
var mongoose = require(‘mongoose’);
var Schema = mongoose.Schema;
var ObjectId = Schema.Types.ObjectId;
var moment = require(‘moment’);
var postFind = require(‘mongoose-post-find’);
var mongooseHidden = require(“mongoose-hidden”)({ defaultHidden: {_id:true,__v:true} });
var stepSchema = new Schema({//加载图片
imgUrl: {
type: String,
required: true
},
timePoint: {//截止时间节点
type: Number
}
},{
id:false,
toObject: {getters: true},
toJSON: {getters: true}
});
//TODO:id及虚拟id的问题
var cardCommentSchema = new Schema({//卡片评论、回复
commentUser: {//评论者
type: ObjectId,
ref: 'UserV2',
required: true
},
targetUser: {//评论对象
type: ObjectId,
ref: 'UserV2'
},
content: {//内容
type: String,
required: true
},
isReported: {//举报
type: Boolean,
default: false
},
createdAt: {
type: Date,
required: true,
default: Date.now
}
},{
id:false,
toObject: {getters: true},
toJSON: {getters: true}
});
var cardSchema = new Schema({
owner: {//卡片作者
type: ObjectId,
ref: ‘UserV2’,
required: true
}, //own user id
title: {//标题
type: String,
required: true,
validate: function (val) {
return val.length <= 20;
}
},
description: {//描述
type: String,
default: ‘’
},
soundStory: {
type: String,
default: ‘’
},
steps: {//图片顺序及播放时间、
type: [stepSchema]
},
comments: {//评论
type: [cardCommentSchema]
},
playUsers: {//播放者
type: [ObjectId]
},
praiseUsers: {//收藏(点赞)者
type: [ObjectId]
},
downloadUsers: {//下载者
type: [ObjectId]
},
sharedUsers: {//分享者
type: [ObjectId]
},
reportUsers: {//举报者
type: [ObjectId]
},
color: {//颜色
type: String,
default: ‘’
},
isRecommended: {//推荐
stateType: {
type: String,
default: ‘undone’,
enum: [‘done’, ‘undone’, ‘waiting’]//推荐过,未被推荐过,等待被推荐
},
recommendAt: {
type: Date
}
},
createdAt: {
type: Date,
required: true,
default: Date.now
},
updatedAt: {
type: Date,
required: true,
default: Date.now
}
}, {
id:false,
toObject: {getters: true},
toJSON: {getters: true}
});
stepSchema.virtual(“stepId”).get(function(){
return this._id
});
cardCommentSchema.virtual(“commentId”).get(function(){
return this._id
});
cardSchema.virtual(“cardId”).get(function(){
return this._id
});
cardSchema.virtual(“commentCount”).get(function () {
return (this.comments && this.comments.length) || 0;
});
cardSchema.virtual(“downloadCount”).get(function () {
return (this.downloadUsers && this.downloadUsers.length) || 0;
});
cardSchema.virtual(“praiseCount”).get(function () {
return (this.praiseUsers && this.praiseUsers.length) || 0;
});
cardSchema.virtual(“sharedCount”).get(function () {
return (this.sharedUsers && this.sharedUsers.length) || 0;
});
cardSchema.virtual(“playCount”).get(function () {
return (this.playUsers && this.playUsers.length) || 0;
});
cardSchema.virtual(“isReported”).get(function () {
return (this.reportUsers && this.reportUsers.length) ? true : false;
});
cardSchema.virtual(“playCount”).get(function(){
return (this.playUsers&&this.playUsers.length)||0;
});
cardSchema.options.toObject.hide = ‘_id’;
cardSchema.options.toObject.transform = function (doc, ret, options) {
// remove the _id of every document before returning the result
delete ret._id;
};
stepSchema.options.toObject.transform = function (doc, ret, options) {
// remove the _id of every document before returning the result
delete ret._id;
};
//cardSchema.plugin(mongooseHidden);
//cardCommentSchema.plugin(mongooseHidden);
//stepSchema.plugin(mongooseHidden);
////cardSchema.plugin(require(‘mongoose-toobject’), { hide: ‘_id’ });
//var postFind = require(‘mongoose-post-find’);
//cardSchema.plugin(postFind, {
//
// find: function(results,done) {
// console.log(cardSchema.options);
// for(var i=0;i<results.length;i++){
// results[i]._doc.cardId = results[i]._id;
// delete results[i]._doc._id;
// delete results[i]._doc.v;
// for(var j=0;j< results[i].steps.length;j++){
// results[i].steps[j]._doc.stepId = results[i].steps[j]._doc._id;
// delete results[i].steps[j]._doc._id;
// }
// }
//
// done(null, results); //Results must be passed to callback
// },
// findOne: [
// function(result, done) {
// result._doc.cardId = result._id;
// delete result._doc._id;
// delete result._doc.v;
// for(var j=0;j< result.steps.length;j++){
// result.steps[j]._doc.stepId = result.steps[j]._doc._id;
// delete result.steps[j]._doc._id;
// }
// done(null, result)
// }
// ]
//});
module.exports = cardSchema;
Node.js测试相关资料
supertest
superagent
mocha
should
API测试工具 Postman