Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/assembly/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mongodb 猫鼬类型错误';无法读取命名空间';Mongoose模块中collection.js中未定义的_Mongodb_Mongoose - Fatal编程技术网

Mongodb 猫鼬类型错误';无法读取命名空间';Mongoose模块中collection.js中未定义的

Mongodb 猫鼬类型错误';无法读取命名空间';Mongoose模块中collection.js中未定义的,mongodb,mongoose,Mongodb,Mongoose,当我使用NPM运行我的应用程序时,它运行没有问题。在使用VSC调试器运行它时,我在位于node_modules/mongodb/lib/collection.js中的collection.js中两次收到以下错误: TypeError: Cannot read property 'namespace' of undefined at Object.get [as dbName] (/xxxx/xxxx/xxxx/xxxx/node_modules/mongodb/lib/collectio

当我使用NPM运行我的应用程序时,它运行没有问题。在使用VSC调试器运行它时,我在位于node_modules/mongodb/lib/collection.js中的collection.js中两次收到以下错误:

TypeError: Cannot read property 'namespace' of undefined
    at Object.get [as dbName] (/xxxx/xxxx/xxxx/xxxx/node_modules/mongodb/lib/collection.js:184:19)
    at Object.<anonymous> (/xxxx/xxxx/xxxx/xxxx/node_modules/mongoose/lib/drivers/node-mongodb-native/collection.js:184:36)
    at Module._compile (internal/modules/cjs/loader.js:689:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)
    at Module.load (internal/modules/cjs/loader.js:599:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
    at Function.Module._load (internal/modules/cjs/loader.js:530:3)
    at Module.require (internal/modules/cjs/loader.js:637:17)
    at require (internal/modules/cjs/helpers.js:22:18)
    at Object.<anonymous> (/xxxx/xxxx/xxxx/xxxx/node_modules/mongoose/lib/drivers/node-mongodb-native/index.js:8:22)
实例2在这里获得:

Object.defineProperty(Collection.prototype, 'dbName', {
  enumerable: true,
  get: function() {
    return this.s.namespace.db;
  }
});
Object.defineProperty(Collection.prototype, 'collectionName', {
  enumerable: true,
  get: function() {
    return this.s.namespace.collection;
  }
});
我在app.js中的连接配置如下所示(在使用NPM运行应用程序时,它可以正常工作,没有任何错误):

此应用程序中唯一加载Mongoose的Mongoose模型如下:

const mongoose = require('mongoose');
const Schema = mongoose.Schema;

// UserSchema has been omitted for privacy
const UserSchema = new Schema({
});

module.exports = User = mongoose.model('User', UserSchema);
没有加载Mongoose模块的其他实例。我还检查了我在
mongoose.connect
方法中传递的选项,它们看起来也不是。此外,我还检查了存储在
env
文件中的值,它们似乎也没有引起问题


谢谢,非常感谢您的帮助

更新nodemon,mongoose

npm i -g nodemon
npm i mongoose
如果您收到程序包依赖项的警告,例如:

npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.11 (node_modules\chokidar\node_modules\fsevents):
=> npm i fsevents

然后再安装可选的依赖项。

更新mongoose v5.8.11。今天(2020年1月31日)发布

供参考-


我刚刚尝试了上述方法,但不幸的是,它没有解决问题。请也更新您的mongoose软件包。是的,按照信中的说明-无法解决问题。
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.11 (node_modules\chokidar\node_modules\fsevents):
=> npm i fsevents