我需要将一个181 KB的json文件插入到mongo集合中,限制是它需要使用mongosh来完成。
json_file_path=/some/path/file.json
json_file_string=$(cat $json_file_path)
/mongo/path/monhosh $databaseName \
--tlsCertificateKeyFile someAuthDetails \
--tlsCAFile someMoreAuthDetails
--quiet \
--eval "db.test_collection.insertOne(${json_file_string})"
这似乎适用于较小的文件,但对于 181 KB 的文件来说,这并不是那么大,它会失败,如下所示:
-ksh: /mongo/path/monhosh: cannot execute [Arguments list too long]
我将 ulimit -s 从 8000 增加到 65000,这似乎是最大值,但运气不佳。有什么想法吗?
我会考虑使用 mongorestore,https://www.mongodb.com/docs/database-tools/mongorestore/
或者你可以安装mongodb compass并手动将json文件导入到集合中