Ai
2 Star 6 Fork 1

island-coder/ExpressApi

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
seed.js 1.81 KB
一键复制 编辑 原始数据 按行查看 历史
岛上码农 提交于 2021-06-29 22:08 +08:00 . initial commit
const { Dynamics } = require("./models/dynamics");
const mongoose = require("mongoose");
const config = require("config");
const data = [
{
title: "Comedy",
movies: [
{ title: "Airplane", numberInStock: 5, dailyRentalRate: 2 },
{ title: "The Hangover", numberInStock: 10, dailyRentalRate: 2 },
{ title: "Wedding Crashers", numberInStock: 15, dailyRentalRate: 2 }
]
},
{
name: "Action",
movies: [
{ title: "Die Hard", numberInStock: 5, dailyRentalRate: 2 },
{ title: "Terminator", numberInStock: 10, dailyRentalRate: 2 },
{ title: "The Avengers", numberInStock: 15, dailyRentalRate: 2 }
]
},
{
name: "Romance",
movies: [
{ title: "The Notebook", numberInStock: 5, dailyRentalRate: 2 },
{ title: "When Harry Met Sally", numberInStock: 10, dailyRentalRate: 2 },
{ title: "Pretty Woman", numberInStock: 15, dailyRentalRate: 2 }
]
},
{
name: "Thriller",
movies: [
{ title: "The Sixth Sense", numberInStock: 5, dailyRentalRate: 2 },
{ title: "Gone Girl", numberInStock: 10, dailyRentalRate: 2 },
{ title: "The Others", numberInStock: 15, dailyRentalRate: 2 }
]
}
];
async function seed() {
await mongoose.connect(config.get("db"));
await Dynamics.deleteMany({});
let dynamics = [];
for (let i = 1; i < 29; i++) {
const dynamic =
{
'title': `标题${i}:这是一个列表标题,最多两行,多处部分将会被截取`,
'imageUrl': 'https://ss1.bdstatic.com/70cFvXSh_Q1YnxGkpoWK1HF6hhy/it/u=688497718,308119011&fm=26&gp=0.jpg',
'viewCount': 180 + i * 10,
'content': `这是标题${i}对应的内容`
}
dynamics.push(dynamic);
}
console.info(dynamics);
await Dynamics.insertMany(dynamics);
mongoose.disconnect();
console.info("Done!");
}
seed();
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
JavaScript
1
https://gitee.com/island-coder/express-api.git
git@gitee.com:island-coder/express-api.git
island-coder
express-api
ExpressApi
master

搜索帮助