gpt4 book ai didi

mongodb - mongoimport 导入csv文件乱序

转载 作者:可可西里 更新时间:2023-11-01 10:19:57 34 4
gpt4 key购买 nike

我有一个 23k 行的 csv 文件。当我从 shell 使用 mongoimport 或从 mongochef 导入时,它以错误的顺序导入。

比如我有

a;b;c;(header)
1;1;1;
2;2;2;
3;3;3;

.csv 文件。当我从 shell 或 mongochef 导入它然后 .find() 结果是;

a|b|c
1;1;1;
3;3;3;
2;2;2;

任何帮助都会很棒。这是我用于导入的 shell 命令;

mongoimport -d local -c test --type csv --file "C:\Program Files\MongoDB\Example Datasets\abc.csv" --headerline --ignoreBlanks

最佳答案

您可以尝试使用 --maintainInsertionOrder选项。

正如文档所说:

If specified, mongoimport inserts the documents in the order of their appearance in the input source, otherwise mongoimport may perform the insertions in an arbitrary order

另请注意,find 默认顺序是 natural order这不能保证按插入顺序返回结果。所以我通常做的是按 _id 字段排序。

关于mongodb - mongoimport 导入csv文件乱序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40179948/

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com