John Oliver
John Oliver

Reputation: 91

Store data as JSON in MongoDB

I am building a digital-card generator app in node.js. In this I want to store the card data as JSON in the MongoDB database. I am using mongoose ODM. but I think mongoose does not support the data-type of Json or object.

The card schema:

const digitalCardSchema = new mongoose.Schema(
  {
    userId: {
      type: mongoose.Schema.Types.ObjectId,
      ref: "User",
      required: true,
    },
    data: {
      type: String,
    },
  },
  {
    timestamps: true,
  }
);

How can I do that?

Upvotes: 0

Views: 309

Answers (1)

Hanoj B
Hanoj B

Reputation: 371

you can try this option - there is a Mixed schema type

https://mongoosejs.com/docs/schematypes.html#mixed

Upvotes: 1

Related Questions