从 csv 导入数据时如何更改 mongodb 中自动生成的 _id 字段?
How to change auto generated _id field in mongodb while importing data from csv?
我正在使用 mongoimport
从 csv
文件导入数据。为此,我执行以下命令
mongoimport -d {databaseName} -c {collectionName}--type csv --file {fileName} --headerline
它使用 objectId 值创建自动生成的_id
字段。并在其上创建索引。
但我希望它不应该为此创建索引。如何在 _id
和那个 csv
文件的字段上创建复合索引?
引用 MongoDB documentation
MongoDB creates the _id index, which is an ascending unique index on the _id field, for all collections when the collection is created. You cannot remove the index on the _id field.
但是您可以创建一个复合索引,其中您的索引可以包含对 _id
字段的引用。
例如,语法为 db.test.ensureIndex({"_id": 1, "name": 1})
,其中 name
是文档中的另一个字段。 More info
我正在使用 mongoimport
从 csv
文件导入数据。为此,我执行以下命令
mongoimport -d {databaseName} -c {collectionName}--type csv --file {fileName} --headerline
它使用 objectId 值创建自动生成的_id
字段。并在其上创建索引。
但我希望它不应该为此创建索引。如何在 _id
和那个 csv
文件的字段上创建复合索引?
引用 MongoDB documentation
MongoDB creates the _id index, which is an ascending unique index on the _id field, for all collections when the collection is created. You cannot remove the index on the _id field.
但是您可以创建一个复合索引,其中您的索引可以包含对 _id
字段的引用。
例如,语法为 db.test.ensureIndex({"_id": 1, "name": 1})
,其中 name
是文档中的另一个字段。 More info