Mongoose同一模式的多个文档

Mongoose同一模式的多个文档,mongoose,mongoose-schema,Mongoose,Mongoose Schema,Noob的问题是,我如何创建同一模式的多个文档而不必声明一个新常量呢。我是否需要为每个键创建一个数组,例如 const newItem = new Item({ name: ["Blue Shirt", "Green Shirt"], image: ["images/image-1.jpg","images/image-2.jpg"], price: [30, 20], quantity: [5,

Noob的问题是,我如何创建同一模式的多个文档而不必声明一个新常量呢。我是否需要为每个键创建一个数组,例如


const newItem = new Item({
  name: ["Blue Shirt", "Green Shirt"],
  image: ["images/image-1.jpg","images/image-2.jpg"],
  price: [30, 20],
  quantity: [5, 10]
});


您必须创建一个数据数组

const newItem = new Item({
  name: "Blue Shirt",
  image: "https://picsum.photos/id/237/200/300",
  price: 30,
  quantity: 5
});

var arr = [newItem]; //Pass array of documents / objects.
Item.insertMany(arr, function(error, docs) {});

您可以在上探索更多内容

const newItem = new Item({
  name: "Blue Shirt",
  image: "https://picsum.photos/id/237/200/300",
  price: 30,
  quantity: 5
});

var arr = [newItem]; //Pass array of documents / objects.
Item.insertMany(arr, function(error, docs) {});
var arr = ['{
  name: "Blue Shirt",
  image: "https://picsum.photos/id/237/200/300",
  price: 30,
  quantity: 5
}', {
  name: "Blue Shirt",
  image: "https://picsum.photos/id/237/200/300",
  price: 30,
  quantity: 5
}]; //Pass array of documents / objects.

Item.insertMany(arr, function(error, docs) {});