如何使用多个索引将数据导入 mongodb
how to import data to mongodb with multiple index
我对 mongodb 很陌生,我刚刚创建了一个 database
名称 Test
,里面有一个名为 projects
的 collection
我有一个 json 文件,其中包含 2 个这样的项目:
{
"-KutvlMPRHGWWTgk1Mh4" : {
"isPrivate" : true,
"proj_contact" : "blMufEZjv6ZmnugDlTruzGwmowI3",
"proj_creator" : "blMufEZjv6ZmnugDlTruzGwmowI3",
"proj_date" : "01/01/2017",
"proj_des" : "this is a testing projectasfasfasgasg",
"proj_name" : "Project",
"proj_pi" : "qCQee2pWGeN9PD3FRXbJpdN7mHT2"
},
"-KvARDkcsCEKZgnM94xH" : {
"isPrivate" : false,
"proj_autho" : [ "Lei0ohIcMBbzVtcQD1AgU4wHBKR2", "OnjEOFSNVpf189J9hAaSFWOZdl42", "0DwfVUeMAraiRxFZTa6xyjn6sfx2", "WHjFSvEo45U7ULzwIQdnUz6ytXp1", "kKTWt36bIifrRzpqNP1l2Gnl3KU2" ],
"proj_contact" : "kKTWt36bIifrRzpqNP1l2Gnl3KU2",
"proj_creator" : "kKTWt36bIifrRzpqNP1l2Gnl3KU2",
"proj_date" : "10/12/2017",
"proj_des" : "this is a test :)",
"proj_name" : "another test",
"proj_pi" : "qCQee2pWGeN9PD3FRXbJpdN7mHT2"
}
}
所以我想将其导入 projects collection
。
我是运行这个命令
mongoimport --db Test --collection projects --file import-file.json
但问题是我得到的结果是 mongodb 仅创建 一个索引 ( 1 id ),其中包含所有内容。
我想要的是在导入之后,mongodb 将为上面的每个项目创建 2 个不同的索引(2 个 ID)
这是目前的结果。我使用的是 Studio 3T
谢谢
您似乎缺少一个花括号(用于嵌套对象本身)
{
{"-KutvlMPRHGWWTgk1Mh4" : {
"isPrivate" : true,
"proj_contact" : "blMufEZjv6ZmnugDlTruzGwmowI3",
"proj_creator" : "blMufEZjv6ZmnugDlTruzGwmowI3",
"proj_date" : "01/01/2017",
"proj_des" : "this is a testing projectasfasfasgasg",
"proj_name" : "Project",
"proj_pi" : "qCQee2pWGeN9PD3FRXbJpdN7mHT2"
}},
{"-KvARDkcsCEKZgnM94xH" : {
"isPrivate" : false,
"proj_autho" : [ "Lei0ohIcMBbzVtcQD1AgU4wHBKR2", "OnjEOFSNVpf189J9hAaSFWOZdl42", "0DwfVUeMAraiRxFZTa6xyjn6sfx2", "WHjFSvEo45U7ULzwIQdnUz6ytXp1", "kKTWt36bIifrRzpqNP1l2Gnl3KU2" ],
"proj_contact" : "kKTWt36bIifrRzpqNP1l2Gnl3KU2",
"proj_creator" : "kKTWt36bIifrRzpqNP1l2Gnl3KU2",
"proj_date" : "10/12/2017",
"proj_des" : "this is a test :)",
"proj_name" : "another test",
"proj_pi" : "qCQee2pWGeN9PD3FRXbJpdN7mHT2"
}}
}
更新:
{
"-KutvlMPRHGWWTgk1Mh4" : {
"isPrivate" : true,
"proj_contact" : "blMufEZjv6ZmnugDlTruzGwmowI3",
"proj_creator" : "blMufEZjv6ZmnugDlTruzGwmowI3",
"proj_date" : "01/01/2017",
"proj_des" : "this is a testing projectasfasfasgasg",
"proj_name" : "Project",
"proj_pi" : "qCQee2pWGeN9PD3FRXbJpdN7mHT2"
}
"-KvARDkcsCEKZgnM94xH" : {
"isPrivate" : false,
"proj_autho" : [ "Lei0ohIcMBbzVtcQD1AgU4wHBKR2", "OnjEOFSNVpf189J9hAaSFWOZdl42", "0DwfVUeMAraiRxFZTa6xyjn6sfx2", "WHjFSvEo45U7ULzwIQdnUz6ytXp1", "kKTWt36bIifrRzpqNP1l2Gnl3KU2" ],
"proj_contact" : "kKTWt36bIifrRzpqNP1l2Gnl3KU2",
"proj_creator" : "kKTWt36bIifrRzpqNP1l2Gnl3KU2",
"proj_date" : "10/12/2017",
"proj_des" : "this is a test :)",
"proj_name" : "another test",
"proj_pi" : "qCQee2pWGeN9PD3FRXbJpdN7mHT2"
}
}
我对 mongodb 很陌生,我刚刚创建了一个 database
名称 Test
,里面有一个名为 projects
的 collection
我有一个 json 文件,其中包含 2 个这样的项目:
{
"-KutvlMPRHGWWTgk1Mh4" : {
"isPrivate" : true,
"proj_contact" : "blMufEZjv6ZmnugDlTruzGwmowI3",
"proj_creator" : "blMufEZjv6ZmnugDlTruzGwmowI3",
"proj_date" : "01/01/2017",
"proj_des" : "this is a testing projectasfasfasgasg",
"proj_name" : "Project",
"proj_pi" : "qCQee2pWGeN9PD3FRXbJpdN7mHT2"
},
"-KvARDkcsCEKZgnM94xH" : {
"isPrivate" : false,
"proj_autho" : [ "Lei0ohIcMBbzVtcQD1AgU4wHBKR2", "OnjEOFSNVpf189J9hAaSFWOZdl42", "0DwfVUeMAraiRxFZTa6xyjn6sfx2", "WHjFSvEo45U7ULzwIQdnUz6ytXp1", "kKTWt36bIifrRzpqNP1l2Gnl3KU2" ],
"proj_contact" : "kKTWt36bIifrRzpqNP1l2Gnl3KU2",
"proj_creator" : "kKTWt36bIifrRzpqNP1l2Gnl3KU2",
"proj_date" : "10/12/2017",
"proj_des" : "this is a test :)",
"proj_name" : "another test",
"proj_pi" : "qCQee2pWGeN9PD3FRXbJpdN7mHT2"
}
}
所以我想将其导入 projects collection
。
我是运行这个命令
mongoimport --db Test --collection projects --file import-file.json
但问题是我得到的结果是 mongodb 仅创建 一个索引 ( 1 id ),其中包含所有内容。
我想要的是在导入之后,mongodb 将为上面的每个项目创建 2 个不同的索引(2 个 ID)
这是目前的结果。我使用的是 Studio 3T
谢谢
您似乎缺少一个花括号(用于嵌套对象本身)
{
{"-KutvlMPRHGWWTgk1Mh4" : {
"isPrivate" : true,
"proj_contact" : "blMufEZjv6ZmnugDlTruzGwmowI3",
"proj_creator" : "blMufEZjv6ZmnugDlTruzGwmowI3",
"proj_date" : "01/01/2017",
"proj_des" : "this is a testing projectasfasfasgasg",
"proj_name" : "Project",
"proj_pi" : "qCQee2pWGeN9PD3FRXbJpdN7mHT2"
}},
{"-KvARDkcsCEKZgnM94xH" : {
"isPrivate" : false,
"proj_autho" : [ "Lei0ohIcMBbzVtcQD1AgU4wHBKR2", "OnjEOFSNVpf189J9hAaSFWOZdl42", "0DwfVUeMAraiRxFZTa6xyjn6sfx2", "WHjFSvEo45U7ULzwIQdnUz6ytXp1", "kKTWt36bIifrRzpqNP1l2Gnl3KU2" ],
"proj_contact" : "kKTWt36bIifrRzpqNP1l2Gnl3KU2",
"proj_creator" : "kKTWt36bIifrRzpqNP1l2Gnl3KU2",
"proj_date" : "10/12/2017",
"proj_des" : "this is a test :)",
"proj_name" : "another test",
"proj_pi" : "qCQee2pWGeN9PD3FRXbJpdN7mHT2"
}}
}
更新:
{
"-KutvlMPRHGWWTgk1Mh4" : {
"isPrivate" : true,
"proj_contact" : "blMufEZjv6ZmnugDlTruzGwmowI3",
"proj_creator" : "blMufEZjv6ZmnugDlTruzGwmowI3",
"proj_date" : "01/01/2017",
"proj_des" : "this is a testing projectasfasfasgasg",
"proj_name" : "Project",
"proj_pi" : "qCQee2pWGeN9PD3FRXbJpdN7mHT2"
}
"-KvARDkcsCEKZgnM94xH" : {
"isPrivate" : false,
"proj_autho" : [ "Lei0ohIcMBbzVtcQD1AgU4wHBKR2", "OnjEOFSNVpf189J9hAaSFWOZdl42", "0DwfVUeMAraiRxFZTa6xyjn6sfx2", "WHjFSvEo45U7ULzwIQdnUz6ytXp1", "kKTWt36bIifrRzpqNP1l2Gnl3KU2" ],
"proj_contact" : "kKTWt36bIifrRzpqNP1l2Gnl3KU2",
"proj_creator" : "kKTWt36bIifrRzpqNP1l2Gnl3KU2",
"proj_date" : "10/12/2017",
"proj_des" : "this is a test :)",
"proj_name" : "another test",
"proj_pi" : "qCQee2pWGeN9PD3FRXbJpdN7mHT2"
}
}