当前位置:网站首页>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);
}
});
边栏推荐
- 信息学奥赛一本通 1337:【例3-2】单词查找树 | 洛谷 P5755 [NOI2000] 单词查找树
- JS implementation prohibits web page zooming (ctrl+ mouse, +, - zooming effective pro test)
- Codeforces Round #804 (Div. 2) - A, B, C
- ByteDance dev better technology salon was successfully held, and we joined hands with Huatai to share our experience in improving the efficiency of web research and development
- 什么是pyc文件
- How to select the Block Editor? Impression notes verse, notation, flowus
- leetcode刷题:二叉树17(从中序与后序遍历序列构造二叉树)
- leetcode刷题:二叉树10(完全二叉树的节点个数)
- 线程池参数及合理设置
- Parler de threadlocal insecurerandom
猜你喜欢
Interviewer: what is the internal implementation of set data types in redis?
618 "low key" curtain call, how can baiqiushangmei join hands with the brand to cross the "uncertain era"?
计算lnx的一种方式
Convolution free backbone network: Pyramid transformer to improve the accuracy of target detection / segmentation and other tasks (with source code)
leetcode刷题:二叉树11(平衡二叉树)
Base du réseau neuronal de convolution d'apprentissage profond (CNN)
[C language] string function and Simulation Implementation strlen & strcpy & strcat & StrCmp
建立自己的网站(16)
实操演示:产研团队如何高效构建需求工作流?
14. Users, groups, and permissions (14)
随机推荐
点云文件的.dat文件读取保存
ByteDance dev better technology salon was successfully held, and we joined hands with Huatai to share our experience in improving the efficiency of web research and development
c语言oj得pe,ACM入门之OJ~
Oracle-表空间管理
DP:树DP
Securerandom things | true and false random numbers
-v parameter of GST launch
USACO3.4 “破锣摇滚”乐队 Raucous Rockers - DP
Win10 x64环境下基于VS2017和cmake-gui配置使用zxing以及opencv,并实现data metrix码的简单检测
Is it safe for Guosen Securities to open an account online?
selenium 元素信息
Elk distributed log analysis system deployment (Huawei cloud)
Leetcode(347)——前 K 个高频元素
nprogress插件 进度条
Ffplay document [easy to understand]
.Net分布式事务及落地解决方案
Scala基础【HelloWorld代码解析,变量和标识符】
Leetcode brush questions: binary tree 11 (balanced binary tree)
Leetcode brush question: binary tree 14 (sum of left leaves)
Go language learning tutorial (XV)