提问者:小点点

Mongoose.connect()中的useNewURLParser和userCreateIndex是做什么的?


我目前是MongoDB和NodeJS的新手,我想知道选项useNewURLParser和useCreateIndex是做什么的。

const mongoose = require("mongoose");

mongoose.connect("mongodb://127.0.0.1:27017/task-manager-api",
{
    useNewUrlParser: true,
    useCreateIndex: true
})


共1个答案

匿名用户

MongoDB有两种连接字符串格式。旧格式现已弃用,并使用旧的URL格式。有MongoDB+SRV:/URL和简单的MongoDB:/URL。如果您使用的是新格式(默认情况下可能是这样),那么新的URL解析器将删除对旧样式URL的支持。

UseCreateIndex:以前MongoDB同样使用EnsureIndex函数调用来确保索引存在,如果索引不存在,则创建索引。也不赞成使用createindexUseCreateIndex选项确保您正在使用新的函数调用。

参考:

https://mongoosejs.com/docs/connections.html#选项https://mongoosejs.com/docs/deprecations.html