mongoose连接数据库(connect函数)
2021/5/23 19:55:40
本文主要是介绍mongoose连接数据库(connect函数),对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
数据库的连接
const mongoose = require('mongoose') // 如果数据库(database)不存在就会创建 mongoose.connect('mongodb://localhost/eg', { useNewUrlParser: true, useUnifiedTopology: true }, function (err) { if (err) console.log('连接数据库失败'); else { console.log('连接数据库成功'); } })
- mongoose.connect函数
function connect( uris: string, options: mongoose.ConnectOptions, callback: (err: MongoError) => void ) //Opens the default mongoose connection.
- 函数返回promise
- uris:'mongoose://username:password@ipadress:port/databaseName'
- options:其中的设置可以覆盖uris中的设置
这篇关于mongoose连接数据库(connect函数)的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-06-26解决google chrome helper 内存占用较高!
- 2024-04-01got an unexpected keyword argument
- 2024-03-30维多利亚的秘密 golang入坑系统
- 2024-03-29mongodb sort by date
- 2024-03-29go swagger
- 2024-03-25mongodb cdc
- 2024-03-25how to use go in vscode
- 2024-03-22mongooseserverselectionerror: connect econnrefused ::1:27017
- 2024-03-21pymongo insert_many
- 2024-03-18projection mongodb