node.js - 新手学习express+mongoose 请问为什么我返回的数据类型看不懂哪些是我需要的,而且获取不到数据
问题描述
问题解答
回答1:图片有点太模糊了,看不清楚,给你看看我之前写的吧,先配置一个Mongoose.js
Mongoose.jsvar mongoose = require(’mongoose’);var config = require(’./Config’);mongoose.connect(config.dbUrl, function (err) { if (err) {console.error(’[数据库链接错误]connect to %s error’, err.message);process.exit(1); }});exports.mongoose = mongoose;
然后写Dao层,用来保存数据库表的操作
Dao/表名.js这是我之前写的一个操作数据库表的js
var dbo = require(’../bin/Mongoose’).mongoose , Schema = dbo.Schema;var u = require(’../bin/Util’);var c = require(’../bin/Config’);//产品所属表var mySchema = Schema({ _id: String, _pid: {type: String, ref: ’product’}, //产品id _sid: {type: String, ref: ’sale’}, //销售id _mid: {type: String, ref: ’merchant’}, //服务商id c_Scan: String, //打开次数 c_Sort: Number, //排序 c_Like: Number, //点赞次数 c_Datetime: String //创建时间});var Chain = dbo.model(’chain’, mySchema);//链接(二维码)//默认添加exports.saveChain = function (u, callback) { var p = new Chain(u); p.save(callback);};//查询 产品 和 销售 对应exports.findPS = function (p, s, callback) { Chain.findOne({_pid: p, _sid: s}, callback);};//查询 按照服务商exports.find = function (mid, callback) { Chain.find({_mid: mid}).populate(’_pid _sid’).sort({’c_Datetime’: -1}).exec(callback);};exports.findSid = function (sid, callback) { Chain.find({_sid: sid}).populate(’_pid _sid’).sort({’c_Datetime’: -1}).exec(callback);};exports.findOne = function (id, callback) { Chain.findOne({_id: id}).populate(’_pid _sid _mid’).exec(callback);};//修改 扫描次数exports.updateScan = function (id, num, options, callback) { Chain.update({_id: id}, {$set: {c_Scan: num}}, options, callback);};//修改 点赞次数exports.updateLike = function (id, num, options, callback) { Chain.update({_id: id}, {$set: {c_Like: num}}, options, callback);};//查询 按照销售exports.findSale = function (sid, skip, callback) { Chain.find({_sid: sid}).populate(’_pid’).sort({’c_Datetime’: -1}).limit(c.loadNum).skip(skip).exec(callback);};//查询 按照销售exports.findSaleWd = function (sid, callback) { Chain.find({_sid: sid}).populate(’_pid’).sort({’c_Datetime’: -1}).exec(callback);};//查询 按照销售exports.findSaleNum = function (sid, id, callback) { Chain.find({_sid: sid, _id: {’$ne’: id}}).populate(’_pid _mid’).sort({’c_Datetime’: -1}).limit(4).skip(0).exec(callback);};exports.updateData=function(pid,data,options,callback){ Chain.update({_pid: pid}, {$set: {c_Datetime: data}}, options, callback);};//查询 按照销售exports.count = function (sid, callback) { Chain.count({_sid: sid}, callback);};//按照销售 全部清空排序exports.updateSortSid = function (id, options, callback) { Chain.update({_id: id}, {$set: {c_Like: 200}}, options, callback);};
希望可以帮助到你。
回答2:router.post(’/homepage’,function(req,res){ var query_doc = {userid:req.body.userid,password:req.body.password}; userModel.findOne(query_doc,function(err,data){if(err) { console.error(err);}if(!!data){ //有这个用户 //todo }else{ //没有这个用户 //todo } })})
你上面打印的应该是这里的日志