【发布时间】:2020-01-21 06:34:25
【问题描述】:
我正在尝试使用 mongoose 的 .it 将许多插入到 mongoDB 中。它只保存 one collection 只是为什么
这是我的代码
https://codesandbox.io/s/gallant-solomon-o91wp
我就这样保存
app.get("/saveData", async () => {
try {
const data = [
{
empid: "test123",
date: "19-Jul-2019"
},
{
empid: "test13",
date: "18-Jul-2019"
},
{
empid: "test13",
date: "11-Jul-2019"
}
];
console.log("before save");
let saveBlog = await BlogPostModel.collection.insertMany(data, {
checkKeys: false
}); //when fail its goes to catch
console.log(saveBlog); //when success it print.
console.log("saveBlog save");
} catch (error) {
console.log(error);
}
});
尝试获取这样的数据
app.get("/filter", async (req, res) => {
try {
let filterBlog = await BlogPostModel.find({});
//when fail its goes to catch
console.log(filterBlog); //when success it print.
res.send(filterBlog);
} catch (error) {
console.log(error);
}
});
只显示一个文档
【问题讨论】:
-
但我有多个文件
-
检查数据库。文件在那里。
-
@AlexBlex
only one文档已保存 -
看我的图片..!!
标签: javascript node.js mongodb mongoose mongoose-schema