首页 > 解决方案 > 为什么即使在成功导入 240 个文件后,总计数仍为零?

问题描述

实际上我正在学习 MongoDB,因为我被卡住以导入 JSON 文件(位于我笔记本电脑的桌面)

我的 JSON 文件是由 240 个元素组成的数组,每个元素的类型都相似,如下所示(我在数组中添加了两个这样的文档,类似地,其他 238 个具有相同形式的文档存在于同一个数组中):-

[
  {
    "id": 1,
    "url": "http://www.tvmaze.com/shows/1/under-the-dome",
    "name": "Under the Dome",
    "type": "Scripted",
    "language": "English",
    "genres": [
      "Drama",
      "Science-Fiction",
      "Thriller"
    ],
    "status": "Ended",
    "runtime": 60,
    "premiered": "2013-06-24",
    "officialSite": "http://www.cbs.com/shows/under-the-dome/",
    "schedule": {
      "time": "22:00",
      "days": [
        "Thursday"
      ]
    },
    "rating": {
      "average": 6.5
    },
    "weight": 91,
    "network": {
      "id": 2,
      "name": "CBS",
      "country": {
        "name": "United States",
        "code": "US",
        "timezone": "America/New_York"
      }
    },
    "webChannel": null,
    "externals": {
      "tvrage": 25988,
      "thetvdb": 264492,
      "imdb": "tt1553656"
    },
    "image": {
      "medium": "http://static.tvmaze.com/uploads/images/medium_portrait/0/1.jpg",
      "original": "http://static.tvmaze.com/uploads/images/original_untouched/0/1.jpg"
    },
    "summary": "<p><b>Under the Dome</b> is the story of a small town that is suddenly and inexplicably sealed off from the rest of the world by an enormous transparent dome. The town's inhabitants must deal with surviving the post-apocalyptic conditions while searching for answers about the dome, where it came from and if and when it will go away.</p>",
    "updated": 1529612668,
    "_links": {
      "self": {
        "href": "http://api.tvmaze.com/shows/1"
      },
      "previousepisode": {
        "href": "http://api.tvmaze.com/episodes/185054"
      }
    }
  },
  {
    "id": 2,
    "url": "http://www.tvmaze.com/shows/2/person-of-interest",
    "name": "Person of Interest",
    "type": "Scripted",
    "language": "English",
    "genres": [
      "Drama",
      "Action",
      "Crime"
    ],
    "status": "Ended",
    "runtime": 60,
    "premiered": "2011-09-22",
    "officialSite": "http://www.cbs.com/shows/person_of_interest/",
    "schedule": {
      "time": "22:00",
      "days": [
        "Tuesday"
      ]
    },
    "rating": {
      "average": 9
    },
    "weight": 96,
    "network": {
      "id": 2,
      "name": "CBS",
      "country": {
        "name": "United States",
        "code": "US",
        "timezone": "America/New_York"
      }
    },
    "webChannel": null,
    "externals": {
      "tvrage": 28376,
      "thetvdb": 248742,
      "imdb": "tt1839578"
    },
    "image": {
      "medium": "http://static.tvmaze.com/uploads/images/medium_portrait/163/407679.jpg",
      "original": "http://static.tvmaze.com/uploads/images/original_untouched/163/407679.jpg"
    },
    "summary": "<p>You are being watched. The government has a secret system, a machine that spies on you every hour of every day. I know because I built it. I designed the Machine to detect acts of terror but it sees everything. Violent crimes involving ordinary people. People like you. Crimes the government considered \"irrelevant\". They wouldn't act so I decided I would. But I needed a partner. Someone with the skills to intervene. Hunted by the authorities, we work in secret. You'll never find us. But victim or perpetrator, if your number is up, we'll find you.</p>",
    "updated": 1535507028,
    "_links": {
      "self": {
        "href": "http://api.tvmaze.com/shows/2"
      },
      "previousepisode": {
        "href": "http://api.tvmaze.com/episodes/659372"
      }
    }
  }
]

我也尝试使用此命令:-
C:\Users\adity>mongoimport --jsonArray --db movie --collection movies --file C:\Users\adity\Desktop\tv-shows.json

我认为数据已经成功导入,因为我得到了这个

C:\Users\adity>mongoimport --jsonArray --db movie --collection movies --file C:\Users\adity\Desktop\tv-shows.json
2021-09-29T12:43:37.247+0530    connected to: mongodb://localhost/
2021-09-29T12:43:37.288+0530    240 document(s) imported successfully. 0 document(s) failed to import.

但是当我运行以下命令时,它向我展示了一些非预期的输出:-

C:\WINDOWS\system32>net start mongoDB
The MongoDB Server (MongoDB) service is starting.
The MongoDB Server (MongoDB) service was started successfully.


C:\WINDOWS\system32>mongo
MongoDB shell version v5.0.3
connecting to: mongodb://127.0.0.1:27017/?compressors=disabled&gssapiServiceName=mongodb
Implicit session: session { "id" : UUID("590da209-aceb-4e56-960b-c950384ee3af") }
MongoDB server version: 5.0.3
================
Warning: the "mongo" shell has been superseded by "mongosh",
which delivers improved usability and compatibility.The "mongo" shell has been deprecated and will be removed in
an upcoming release.
We recommend you begin using "mongosh".
For installation instructions, see
https://docs.mongodb.com/mongodb-shell/install/
================
---
The server generated these startup warnings when booting:
        2021-09-29T13:39:59.232+05:30: Access control is not enabled for the database. Read and write access to data and configuration is unrestricted
---
---
        Enable MongoDB's free cloud-based monitoring service, which will then receive and display
        metrics about your deployment (disk utilization, CPU, operation statistics, etc).

        The monitoring data will be available on a MongoDB website with a unique URL accessible to you
        and anyone you share the URL with. MongoDB may use this information to make product
        improvements and to suggest MongoDB products and deployment options to you.

        To enable free monitoring, run the following command: db.enableFreeMonitoring()
        To permanently disable this reminder, run the following command: db.disableFreeMonitoring()
---
WARNING: some history file lines were truncated at 4095 bytes.
> show dbs
admin   0.000GB
config  0.000GB
local   0.000GB
movie   0.001GB
test    0.000GB
> use movie
switched to db movie
> db.movie.find().count()
0
> db.movie.find().pretty()
>

我正在使用 Windows 操作系统。

有人可以帮助我为什么我将 count 的值设为吗?

标签: databasemongodbsqlitemongodb-querymongodb-.net-driver

解决方案


尝试使用 Studio 3T ( https://studio3t.com/download/ )。GUI 支持导入/导出 JSON/CSV 等。


推荐阅读