Calling mongoose from react client side

后端 未结 2 633
攒了一身酷
攒了一身酷 2021-01-23 05:13

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



        
2条回答
  •  礼貌的吻别
    2021-01-23 05:41

    From the comment here

    Mongoose won't work in the frontend because it relies on functionality from Node which isn't present in browser JS implementations. You can't import Mongoose into frontend code.


    Try importing mongoose in your react app

    import mongoose from "mongoose";

    and iterating through its properties:

    Object.getOwnPropertyNames(mongoose).forEach(prop => {
      console.log(prop);
    });
    

    You'll get

    Promise
    PromiseProvider
    Error
    Schema
    Types
    VirtualType
    SchemaType
    utils
    Document
    

    The methods that you need to work with MongoDB, such as connect, are not being imported.

提交回复
热议问题