前端学习(1338):mongoDB删除文档
生活随笔
收集整理的這篇文章主要介紹了
前端学习(1338):mongoDB删除文档
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
const mongoose = require('mongoose');
mongoose.connect('mongodb://localhost/playground', { useUnifiedTopology: true }).then(() => console.log('數據庫連接成功')).catch(err => console.log(err, '數據庫連接失敗'))//創建集合規則
const courseSchema = new mongoose.Schema({name: String,age: Number,email: String,password: String,hobbies: [String]
});
//使用集合并應用規則
const User = mongoose.model('User', courseSchema);
//查找到一條文檔并且刪除
User.findOneAndDelete({ _id: '5c09f1e5aeb04b22f8460965' }).then(result => console.log(result));
//刪除多條數據
User.deleteMany({}).then(result => console.log(result));
運行結果
總結
以上是生活随笔為你收集整理的前端学习(1338):mongoDB删除文档的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Oracle数据库常见版本
- 下一篇: 前端学习(542):node得环境搭建