【问题标题】:Mongoimport upsert problemMongoimport upsert问题
【发布时间】:2011-08-11 04:47:21
【问题描述】:

我有这个 JSON 的文件

{
_id :     10000000042,
OtherID: 10000000043,
}

C:\mongodb-win32-i386-1.9.0\bin>mongoimport.exe --host localhost --db crm --collection tst --file c:\temp\tst3.txt --jsonArray --upsert --upsertFields 其他ID

连接到:localhost 导入了 1 个对象

在 mongo 控制台中:

    > db.tst.find();
    { "_id" : NumberLong("10000000042"), "OtherID" : NumberLong("10000000043") }

> db.tst.getIndexes()
[
        {
                "name" : "_id_",
                "ns" : "crm.tst",
                "key" : {
                        "_id" : 1
                },
                "v" : 0
        },
        {
                "_id" : ObjectId("4e435d7a296ca66d8f50b0e0"),
                "ns" : "crm.tst",
                "key" : {
                        "OtherID" : 1
                },
                "name" : "OtherID_1",
                "v" : 0
        }
]

然后我更新我的 JSON:

{
_id :     10000000042,
OtherID: 10000000044,
}

然后再次运行 mongoimport

在控制台中:

    > db.tst.find();
    { "_id" : NumberLong("10000000042"), "OtherID" :NumberLong("10000000043") }

OtherID 字段未更新。

我的手断了?

【问题讨论】:

    标签: mongodb


    【解决方案1】:

    删除“upsertFields”参数,你就可以了。您在此处尝试执行的操作不需要这样做。

    【讨论】:

    • 雷蒙,谢谢。我之前试过这个,但它不起作用。但并非一切都好,它有效!
    猜你喜欢
    • 2020-12-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-07-06
    相关资源
    最近更新 更多