【发布时间】:2018-12-24 04:52:58
【问题描述】:
我有一些原始 JSON 已填充用于测试目的,但现在我想使用 mongoDB Compass 将其放入 mongoDB 数据库中。
我的 mongoDB 连接字符串正在运行,并且我的 mongoose 代码正在运行。
我该怎么做?
我希望这将是一项简单的任务,因为 mongoDB 已经以 BSON 的形式存储它的数据。
这是我的代码的 sn-p。
const json_string =
`[
{
"link": "https://www.youtube.com/watch?v=BMOjVYgYaG8",
"image": "https://i.imgur.com/Z0yVBpO.png",
"title": "Debunking the paelo diet with Christina Warinner",
// ... snip
},
{ // ... snip
架构已创建:
// for relevant data from google profile
schema.Article = new Schema({
link: { type: String, required: true },
image: { type: String, required: true },
title: { type: String, required: true },
summary: { type: String, required: true },
tag: { type: String, required: true },
domain: { type: String, required: true },
date: { type: String, required: true },
timestamp: { type: Date, default: Date.now }
});
【问题讨论】:
-
MongoDB 不将其数据存储在 JSON 中!它存储结构化数据,是的,但是 JSON 是这种结构的字符串表示形式……而且您的数据库绝对不是(或不应该是)一堆字符串。
-
显然是BSON,类似...en.wikipedia.org/wiki/BSON...更新
标签: javascript json mongodb mongoose bson