当前位置: 首页 > news >正文

微信公众号怎样发布wordpressseo赚钱培训

微信公众号怎样发布wordpress,seo赚钱培训,广告在线设计网站,广告设计与制作专业主要学什么本项目旨在学习如何快速使用 nodejs 开发后端api,并为以后开展其他项目的开启提供简易的后端模版。(非后端工程师) 由于文档是代码写完之后,为了记录项目中需要注意的技术点,因此文档的叙述方式并非开发顺序&#xff0…

本项目旨在学习如何快速使用 nodejs 开发后端api,并为以后开展其他项目的开启提供简易的后端模版。(非后端工程师)
由于文档是代码写完之后,为了记录项目中需要注意的技术点,因此文档的叙述方式并非开发顺序(并非循序渐进的教学文档)。建议配合项目源码node-mongodb-template 。

【NodeJS】NodeJS+mongoDB在线版开发简单RestfulAPI (一):项目简介及安装依赖

【NodeJS】NodeJS+mongoDB在线版开发简单RestfulAPI (二):项目文件夹架构及路由的设置

【NodeJS】NodeJS+mongoDB在线版开发简单RestfulAPI (三):Cors的设置及.env文件的设置

【NodeJS】NodeJS+mongoDB在线版开发简单RestfulAPI (四):状态码的使用

【NodeJS】NodeJS+mongoDB在线版开发简单RestfulAPI (五):POST上传文件的设置

【NodeJS】NodeJS+mongoDB在线版开发简单RestfulAPI (六):token的设置

【NodeJS】NodeJS+mongoDB在线版开发简单RestfulAPI (七):MongoDB的设置

【NodeJS】NodeJS+mongoDB在线版开发简单RestfulAPI (八):API说明(暂时完结,后续考虑将在线版mongoDB变为本地版)

MongoDB的设置

选择了MongoDB的在线版数据库,可以申请免费的空间使用,点击网址申请。申请和创建库之后,复制针对nodejs提供的code,如下

mongodb+srv://db:<db_password>@test.gx6wc.mongodb.net/?retryWrites=true&w=majority&appName=test

将其中<db_password>替换成你设置的密码。

接下来就可以在nodejs中使用该云数据库了。

连接数据库

  • 安装依赖

pnpm i --save mongoose

  • 引用依赖
//app.js
const mongoose = require('mongoose');
  • 连接数据库
mongoose.connect('mongodb+srv://db:'
+process.env.MONGO_ATLAS_PW
+'@test.gx6wc.mongodb.net/?retryWrites=true&w=majority&appName=test');mongoose.Promise = global.Promise;

mongoose API学习

Model数据结构声明
Type数据类型
  • mongoose.Schema.Types.ObjectId 自动生成的id;
  • Number 数字型;
  • String 字符串型;
required:是否必要
default:默认值
ref:关联的表/数据结构/model
unique:是否唯一
match:数据正则检查匹配
定义数据结构

mongoose.Schema({...})

mongoose.model('<modelName>', <ModelSchema>)

//product.js
const mongoose = require('mongoose');const productSchema = mongoose.Schema({_id:mongoose.Schema.Types.ObjectId,name:{type:String, required:true},price:{type:Number, required:true},productImage:{type:String, required:true},
})module.exports = mongoose.model('Product', productSchema);
//order.js
const mongoose = require('mongoose');const orderSchema = mongoose.Schema({_id:mongoose.Schema.Types.ObjectId,//product的值为ObjectId,与【Product】关联product:{type:mongoose.Schema.Types.ObjectId, required:true,ref:'Product'},quantity:{type:Number, default:1},
})module.exports = mongoose.model('Order', orderSchema);
//user.js
const mongoose = require('mongoose');const userSchema = mongoose.Schema({_id:mongoose.Schema.Types.ObjectId,email:{type:String, required:true,unique:true,//校验email的格式match:/(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*|"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])*")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\[(?:(?:(2(5[0-5]|[0-4][0-9])|1[0-9][0-9]|[1-9]?[0-9]))\.){3}(?:(2(5[0-5]|[0-4][0-9])|1[0-9][0-9]|[1-9]?[0-9])|[a-z0-9-]*[a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)\])/},password:{type:String, required:true},
})module.exports = mongoose.model('User', userSchema);
数据操作
类型引用
//product Model定义的位置
const Product = require('../models/product');
exec: 执行

执行mongoose的query操作后,调用exec()方法;

Product.find().then();
Product.find().exec().then();

区别在于: mongoose 的所有查询操作返回的结果都是 query (官方文档是这样写的),并非一个完整的promise。
而加上.exec()则将会返回成为一个完整的 promise 对象,但是其是 mongoose 自行封装的 promise ,与 ES6 标准的 promise 是有所出入的(你应该会在控制台看到相关的警告),而且官方也明确指出,在未来的版本将会废除自行封装的promise,改为 ES6 标准,因此建议楼主在使用过程中替换为 ES6 的 promise,如下:

const mongoose = require(‘mongoose’);
mongoose.Promise = global.Promise;

find: 查询
//查询全部
Product.find();
Product.find().exec().then(docs=>{//docs是products数组
});//查找所有满足条件的数据
//条件格式 {prop:value,...}
User.find({email: req.body.email}).exec().then(docs=>{//docs是数组
})//查询满足条件的数据中的第一个
Product.findOne();
User.findOne({email: req.body.email}).exec().then(doc=>{//doc是一个对象
})//查询指定Id的数据(id唯一)
Product.findById();
Product.findById(id).exec().then(doc=>{//doc是一个对象
})Product.findOneAndDelete();
Product.findOneAndReplace();
Product.findOneAndUpdate()
where: 查询条件
Product.where({email: req.body.email}).fineOne().exec().then(doc=>{});
select: 指定属性
//Product包含属性:name, price, _id//需求是只显示name和price
Product.find().select('name price').exec().then(docs=>{//docs是products数组
});
populate: 子表属性
//Order包含属性:product quantity _id
//product是子表数据的_id//需求是显示product的详细属性
Order.find().select('product quantity').populate('product','name price').exec().then(docs=>{});
//{
//  product:{
//    name:"",
//    price:11
//  },
//  quantity:1,
//}
save: 新增
const product = new Product({_id:new mongoose.Types.ObjectId(),name:req.body.name,price:req.body.price,productImage:req.file.path});
product.save().then(result=>{//result和product实例相同})
updateOne: 修改
const updateOpts = {name:"",price:22,
};
//找到指定id的数据,并修改对应字段
Product.updateOne({_id:id},{$set:updateOpts}).exec().then(result=>{      
})
deleteOne: 删除
Product.deleteOne({_id:id}).exec().then(result=>{     
})
http://www.yidumall.com/news/12461.html

相关文章:

  • 大连网站建设1000元永州网站seo
  • 浏览网站怎么用手机做中国突然宣布大消息
  • zblog转移到wordpress搜狗网站seo
  • 化工行业网站设计海南百度总代理
  • 17网站一起做网批网络整合营销4i原则
  • 公司网站建设费用网络推广公司简介模板
  • 阿里云服务器做网站需要备案云南网络推广seo代理公司
  • 微网站不能分享朋友圈google推广 的效果
  • 人和动物做的电影网站google谷歌搜索引擎入口
  • java网站开发教程 百度云网络营销的方式与手段
  • 谁能给做网站如何查看网站收录情况
  • wordpress 编写手机主题百度关键词优化点击 教程
  • 免费的网站建设长沙网站seo哪家公司好
  • ps如何做网站轮播图百度推广在哪里能看到
  • 专业做电子的外贸网站seo优化一般包括
  • wordpress快照黑帽劫持天津优化公司
  • 虚拟专用网络服务器徐州seo管理
  • 利用php做网站教程网络营销有哪些模式
  • 网站开发实践体会百度推广后台登录首页
  • 石柱网站开发全网营销与seo
  • 几十万做网站平台营销网站
  • 西安建设商城类网站成都百度seo公司
  • 网站规划与开发实训室建设seo下载站
  • 网站服务器备案查询网站2022最火营销方案
  • 英文网站建设汕头疫情最新消息
  • 阿里云怎么做淘宝客网站有哪些推广平台和渠道
  • 精品课程教学网站廊坊自动seo
  • 做网站图标的软件网络seo是什么工作
  • 代码生成器怎么用互联网seo是什么
  • 泉州网站制作设计网站片区