开发者

How to store Array in Array Object ? please solution to this question . and explain which changes are required

    const serviceAndProduct = async (req, res) => {
  try {
    let {
      serviceName,
      subServiceId,
      serviceId,
      title,
      text,
      id,
      oldTitle,
      newTitle,
      newText,
      oldurl,
      dotId,
      dotName,
      slug,
    } = req.body;
    const options = {
      replacement: "", // replace spaces with replacement character, defaults to `-`
      remove: undefined, // remove characters that match regex, defaults to `undefined`
      lower: true, // convert to lower case, defaults to `false`
      strict: true, // strip special characters except replacement, defaults to `false`
      locale: "en", // language code of the locale to use
    };
    let slugData = slugify(req.body.title, options);
    let checkData = await ServiceAndProduct.findOne({ _id: id });
    if (checkData === null) {
      let logCoin = new Blockchain();
      console.log("mining logcoin in progress...");
      logCoin.addNewBlock(
        new Block(0, new Date().toLocaleString(), {
          serviceName: serviceName,
          serviceId: mongoose.Types.ObjectId(serviceId),
          title: title,
          text: text,
          imageName: req.file.filename,
          imageUrl: req.fileurl,
          slug: slugData,
          [{
            dotId: mongoose.Types.ObjectId(dotId),
          dotName: dotName
          }],
                    
        })
      );
      res.send({
        status: HttpCode.OK,
        message: HttpMessage.BLOCK_ADDED,
      });
    } else {
      console.log(req.fileurl);
      let updateData = await ServiceAndProduct.updateOne(
        { _id: id, "data.title": oldTitle },
        {
          $set: {
            "data.$.title": title,
            "data.$.text": text,
            "data.$.serviceName": serviceName,
            "data.$.serviceId": mongoose.Types.ObjectId(serviceId),
            "data.$.slug": slugData,
            // "data.$.imageName": req.file.filename?req.file.filename:'',
            "data.$.imageUrl":
              req.fileurl && req.fileurl != "" ? req.fileurl : oldurl,
            timestamp: new Date().toLocaleString(),
          },
        }
      );
      if (updateData.modifiedCount === 1) {
        res.send({
          status: HttpCode.OK,
          message: HttpMessage.BLOCK_UPDATED,
        });
      } else {
        res.send({
          status: HttpCode.BAD_REQUEST,
          message: HttpMessage.BLOCK_NOT_UPDATED,
        });
      }
    }
  } catch (error) {
    console.log(error);
    res.send(error);
  }
};

and this was a model of API How to store Array in Array Object ?please solution to this question and explain which changes are required and this was a model of API How to store Array in Array Object ?please solution to this question and explain which changes are required and this was a model of API How to store Array in Array Object ?please solution to this question and explain which changes are required and this was a model of API How to store Array in Array Object ?please solution to this question and explain which changes are required

const serviceAndProductSchema=new mongoose.Schema({
    index:{
        type开发者_开发问答:Number,
        require:false
    },
    // timestamp:{
    //     type:String,
    //     require:false
    // },
    previousHash:{
        type:String,
        require:false
    },
    hash:{
        type:String,
        require:false
    },
    data:{
        type:Array,
        require:false
    },
    

},
{timestamp:true}
);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜