【问题标题】:Loading data into my Mongo Database but unexpected 'O'将数据加载到我的 Mongo 数据库但意外的“O”
【发布时间】:2020-04-22 23:16:04
【问题描述】:

我有一个查询,我正在尝试将数据 JSON 加载到我的 mongodb 中,但意外的“O”(ObjectId)没有运气。以下内容取自 Git Bash。

{
        "_id" : ObjectId("5e9f36d8246c0a6d0881d52c"),
        "name" : "Miley",
        "type" : "Dog",
        "image" : "https://images.unsplash.com/photo-1558233043-45af001ed5b7?ixlib=rb- 
          1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1350&q=80",
        "description" : "Fun, Clever, Energetic and looking for her forever home ",
        "location" : "Dublin, Ireland",
        "site" : "  https://www.facebook.com/DroghedaAnimalRescue/",
        "author" : {
                "id" : ObjectId("5e9ee03ea12b1c7f80a7af8c"),
                "username" : "Johnny"
        },
        "__v" : 0
}

【问题讨论】:

  • but getting no luck你能说得更具体些吗

标签: node.js json mongodb


【解决方案1】:

想通了,需要在ObjectID周围加“$”

{
    "_id": {
        "$ObjectId": "5ea0d96ebbfbef0004f8d88e"
    },
    "name": "Miley",
    "type": "Dog",
    "image": "https://images.unsplash.com/photo-1558233043-45af001ed5b7?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1350&q=80",
    "description": "Fun, Clever, Energetic and looking for her forever home ",
    "location": "Dublin, Ireland",
    "site": "https://www.facebook.com/DroghedaAnimalRescue/",
    "author": {
        "id": {
            "$ObjectId": "5ea0bea88b2459000492dab7"
        },
        "username": "Animal Rescue"
    },
    "__v": 0
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-09-13
    • 1970-01-01
    • 2012-12-27
    • 2013-07-31
    相关资源
    最近更新 更多