Как написать схему для этого кода в узле. js - PullRequest
0 голосов
/ 17 февраля 2020
 _id :hhjjdfghjkkmdfghjkl8888
  orderDetail:
  [
     {
        fitoName:,
        fitoCode:,
        ProviderName:
        ProviderCode:
        Quantity:
        storUrl:fitotouch.com/fivestart/chinasore
     },
     {
        fitoName:,
        fitoCode:,
        ProviderName:
        ProviderCode:
        Quantity:
        storUrl:fitotouch.com/fivestart/chinasore
     }  
  ]
}

Ответы [ 2 ]

2 голосов
/ 28 февраля 2020

вы можете сделать это, используя этот метод

var mongoose = require('mongoose');

mongoose.connect('mongodb://localhost/mongoose_basics');

var authorSchema = mongoose.Schema({
    _id: mongoose.Schema.Types.ObjectId,
    name: {
            firstName: String,
        lastName: String
    },
    biography: String,
    twitter: String,
    facebook: String,
    linkedin: String,
    profilePicture: Buffer,
    created: { 
        type: Date,
        default: Date.now
    }
});

var Author = mongoose.model('Author', authorSchema);

используйте этот ссылочный URL: https://code.tutsplus.com/articles/an-introduction-to-mongoose-for-mongodb-and-nodejs--cms-29527

1 голос
/ 17 февраля 2020

Вы можете сделать это так:

const mongoose = require("mongoose");

const OrderDetails = mongoose.Schema(
  {
    fitoName: String,
    fitoCode: String,
    providerName: String,
    providerCode: String,
    quantity: Number,
    storUrl: String
  },
  { _id: false } // If you don't want an ID to be created by MongoDB
);

const Orders = mongoose.model(
  "orders",
  new mongoose.Schema(
    {
      orderDetail: {
        type: [OrderDetails],
        required: true
      }
    },
    { timestamps: true }
  )
);
...