Mongoimport在同一文档内

时间:2018-09-23 16:41:01

标签: mongodb mongoimport

我正在使用import语句

mongoimport -c <collection> -d <db> --mode merge --file test.json

将json文档上传到Mongo。但是,每次新导入似乎都会创建一个新文档。由于这是一个高手,所以我希望进入现有文档并根据ID插入/更新。例如,在下面的示例中,不应插入,因为它们完全匹配。

{
"_id" : ObjectId("5ba7896fde583898f699d01b"),
"mydata" : [
    {
        "id" : 1,
        "first_name" : "Jeanette",
        "last_name" : "Penddreth",
        "email" : "jpenddreth0@census.gov",
        "gender" : "Female",
        "ip_address" : "26.58.193.2"
    },
    {
        "id" : 2,
        "first_name" : "Giavani",
        "last_name" : "Frediani",
        "email" : "gfrediani1@senate.gov",
        "gender" : "Male",
        "ip_address" : "229.179.4.212"
        }
    ]
}
{
"_id" : ObjectId("5ba78975de583898f699d020"),
"mydata" : [
    {
        "id" : 1,
        "first_name" : "Jeanette",
        "last_name" : "Penddreth",
        "email" : "jpenddreth0@census.gov",
        "gender" : "Female",
        "ip_address" : "26.58.193.2"
    },
    {
        "id" : 2,
        "first_name" : "Giavani",
        "last_name" : "Frediani",
        "email" : "gfrediani1@senate.gov",
        "gender" : "Male",
        "ip_address" : "229.179.4.212"
        }
    ]
}

如何将所有将来的数据导入现有的mydata文档中,并根据其中的ID进行比较?

0 个答案:

没有答案