前端学习(1336):从数据库查询文档
生活随笔
收集整理的這篇文章主要介紹了
前端学习(1336):从数据库查询文档
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
const mongoose = require('mongoose');
mongoose.connect('mongodb://localhost/playground', { useUnifiedTopology: true }).then(() => console.log('數(shù)據(jù)庫連接成功')).catch(err => console.log(err, '數(shù)據(jù)庫連接失敗'))//創(chuàng)建集合規(guī)則
const courseSchema = new mongoose.Schema({name: String,age: Number,email: String,password: String,hobbies: [String]
});
//使用集合并應(yīng)用規(guī)則
const User = mongoose.model('User', courseSchema);//查詢用戶里面得所有命令
//User.find().then(result => console.log(result));
//查詢一條 數(shù)據(jù)不存在 返回得是一個空數(shù)組
User.find({ _id: '5c09f1e5aeb04b22f8460965' }).then(result => console.log(result));
運行結(jié)果
創(chuàng)作挑戰(zhàn)賽新人創(chuàng)作獎勵來咯,堅持創(chuàng)作打卡瓜分現(xiàn)金大獎總結(jié)
以上是生活随笔為你收集整理的前端学习(1336):从数据库查询文档的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Google Chrome Frame
- 下一篇: 前端学习(1305):项目依赖