Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/elixir/2.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
Node.js 使用mongoose和Retrieve在momgodb中保存图像或背景图像列表,作为要附加到用户帖子上的图像输入选择_Node.js_Reactjs_Mongodb_Express_Mern - Fatal编程技术网

Node.js 使用mongoose和Retrieve在momgodb中保存图像或背景图像列表,作为要附加到用户帖子上的图像输入选择

Node.js 使用mongoose和Retrieve在momgodb中保存图像或背景图像列表,作为要附加到用户帖子上的图像输入选择,node.js,reactjs,mongodb,express,mern,Node.js,Reactjs,Mongodb,Express,Mern,我正在进行一个MERN项目,试图添加其他功能, 我想让选择输入图像列表预先存储在MongoDB中,显示在相机图标附近,相机图标是主要的照片输入图标,这样用户可以从选择中选择额外的图像,并在单击post按钮之前添加到他的帖子中 如果用户没有在选择中选择额外的图像,结果将在文本上显示2图像,并且仅显示一个图像 这是后模型模式 import mongoose from 'mongoose' import crypto from 'crypto' const PostSchema = new mon

我正在进行一个MERN项目,试图添加其他功能, 我想让选择输入图像列表预先存储在
MongoDB
中,显示在相机图标附近,相机图标是主要的照片输入图标,这样用户可以从选择中选择额外的图像,并在单击post按钮之前添加到他的帖子中

如果用户没有在选择中选择额外的图像,结果将在文本上显示
2图像
,并且仅显示一个图像

这是后模型模式

 import mongoose from 'mongoose'
import crypto from 'crypto'
const PostSchema = new mongoose.Schema({
  text: {
    type: String,
    required: 'Name is required'
  },
  photo: {
    data: Buffer,
    contentType: String
  },
  ribbon:[
    {
    ribbon1: {
      data: Buffer,
      contentType: String
    },
    ribbon2: {
      data: Buffer,
      contentType: String
    },
    ribbon3: {
      data: Buffer,
      contentType: String
    },
    ribbon4: {
      data: Buffer,
      contentType: String
    },
    ribbon5: {
      data: Buffer,
      contentType: String
    },
    ribbon6: {
      data: Buffer,
      contentType: String
    },
    ribbon7: {
      data: Buffer,
      contentType: String
    },
    ribbon8: {
      data: Buffer,
      contentType: String
    },
    ribbon9: {
      data: Buffer,
      contentType: String
    },
    ribbon10: {
      data: Buffer,
      contentType: String
    },

  }

  ] ,

  likes: [{type: mongoose.Schema.ObjectId, ref: 'User'}],
  comments: [{
    text: String,
    created: { type: Date, default: Date.now },
    postedBy: { type: mongoose.Schema.ObjectId, ref: 'User'}
  }],
  postedBy: {type: mongoose.Schema.ObjectId, ref: 'User'},
  created: {
    type: Date,
    default: Date.now
  },



})

export default mongoose.model('Post', PostSchema) 

你已经写了一些代码了吗?如果是这样的话,请与我们分享一个简单的示例,这样我们就可以找出您的问题所在。是的,我只是添加了后期模型架构,其中ribbon是我希望用户可以选择的图像列表数组。。我试着像处理用户上传的图片一样处理它,但不确定是否是处理它的最佳方式。你已经写了一些代码了吗?如果是这样的话,请与我们分享一个简单的示例,这样我们就可以找出您的问题所在。是的,我只是添加了后期模型架构,其中ribbon是我希望用户可以选择的图像列表数组。。我试着像处理用户上传的图片一样处理它,但不确定这是否是最好的处理方式