当前位置:网站首页>model方法
model方法
2022-07-05 20:11:00 【为什么不好好卖蛋饼】
17 Model 方法
Model是构造函数
Model.create(doc(s),[callback])
创建一个文档并添加到数据库
参数 doc(s) 可以是一个文档对象,也可以是数组。
callback 可选 当操作完成后调用的回调函数。
//查询
Model.find()
condition-查询条件
projection 投影 需要获取到的字段
两种方式
{
name:1,_id:0}
"name age -_id"
option--查询选项 skip limit
callback 回调函数 回调函数必须传,如果不穿,不会查询。
//总会返回数组
StuModel.find({
name:"唐僧"},function(err,docs){
if(!err){
console.log(docs);
}
}
);
StuModel.find({
},{
name:1,_id:0},function(err,docs){
if(!err){
//doc是Document文档对象,是model的实例。
console.log(docs);
}
}
);
StuModel.find({
},"name age -_id",function(err,docs){
if(!err){
console.log(doc instanceof StuModel);
}
}
);
修改
conditions 查询条件
doc 修改后的对象
options 配置参数
callback 回调函数
StuModel.updateOne({
name:"唐僧"},{
$set:{
age:20}},function(err){
if(!err){
console.log("修改成功");
}
});
删除
StuModel.remove({
name:"白骨精"},function(err){
if(!err){
console.log("删除成功");
}
});
统计数量 Count
Model.count(conditions,[callback])
StuModel.count({},function(err,count){
if(!err){
console.log(count);
}
});
边栏推荐
- Oracle-表空间管理
- Wildcard selector
- Complete interview questions for interviewers and senior Android engineers in front-line Internet enterprises
- 深度学习 卷积神经网络(CNN)基础
- CCPC 2021威海 - G. Shinyruo and KFC(组合数,小技巧)
- Database logic processing function
- 建立自己的网站(16)
- Multi branch structure
- Debezium series: record the messages parsed by debezium and the solutions after the MariaDB database deletes multiple temporary tables
- Wechat applet regular expression extraction link
猜你喜欢

港股将迎“最牛十元店“,名创优品能借IPO突围?

Debezium series: record the messages parsed by debezium and the solutions after the MariaDB database deletes multiple temporary tables

S7-200smart uses V90 Modbus communication control library to control the specific methods and steps of V90 servo

IC科普文:ECO的那些事儿

Scala基础【HelloWorld代码解析,变量和标识符】

leetcode刷题:二叉树16(路径总和)

Fundamentals of deep learning convolutional neural network (CNN)

基础篇——配置文件解析

Solve the problem that the database configuration information under the ThinkPHP framework application directory is still connected by default after modification

Elk distributed log analysis system deployment (Huawei cloud)
随机推荐
leetcode刷题:二叉树15(找树左下角的值)
leetcode刷题:二叉树13(相同的树)
CADD课程学习(7)-- 模拟靶点和小分子相互作用 (半柔性对接 AutoDock)
js实现禁止网页缩放(Ctrl+鼠标、+、-缩放有效亲测)
kubernetes资源对象介绍及常用命令(五)-(ConfigMap&Secret)
1: Citation;
基础篇——配置文件解析
leetcode刷题:二叉树11(平衡二叉树)
什么是pyc文件
How to safely and quickly migrate from CentOS to openeuler
【c语言】快速排序的三种实现以及优化细节
sun.misc.BASE64Encoder报错解决方法[通俗易懂]
零道云新UI设计中
《乔布斯传》英文原著重点词汇笔记(十二)【 chapter ten & eleven】
实操演示:产研团队如何高效构建需求工作流?
Win10 x64环境下基于VS2017和cmake-gui配置使用zxing以及opencv,并实现data metrix码的简单检测
浅浅的谈一下ThreadLocalInsecureRandom
CCPC 2021威海 - G. Shinyruo and KFC(组合数,小技巧)
信息学奥赛一本通 1337:【例3-2】单词查找树 | 洛谷 P5755 [NOI2000] 单词查找树
MySql的root密码忘记该怎么找回