本文介绍了从客户端调用猫鼬的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是的,我知道我应该从服务器端调用它.但是目的是从react-redux应用程序调用MongoDB strait.就像Firebase无服务器应用程序一样.我写
Yes, I know I should call it from server side. But the purpose is to invoke MongoDB strait from the react-redux app. It's like firebase serverless apps do.I write
import mongoose from 'mongoose';
let mongoDB = 'mongodb://127.0.0.1/my_database';
mongoose.connect(mongoDB);
mongoose.Promise = global.Promise;
let db = mongoose.connection;
db.on('error', console.error.bind(console, 'MongoDB connection error:'));
然后我得到:
TypeError: __
WEBPACK_IMPORTED_MODULE_6_mongoose___default.a.connect is not a function
如何解决这个问题?
推荐答案
来自注释
尝试在您的React应用程序中导入猫鼬
Try importing mongoose in your react app
import mongoose from "mongoose";
并遍历其属性:
Object.getOwnPropertyNames(mongoose).forEach(prop => {
console.log(prop);
});
你会得到
Promise
PromiseProvider
Error
Schema
Types
VirtualType
SchemaType
utils
Document
未导入需要与MongoDB配合使用的方法,例如connect
.
The methods that you need to work with MongoDB, such as connect
, are not being imported.
这篇关于从客户端调用猫鼬的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!