As per the mongodb documentation, stopOnError option forces mongoimport to halt the import operation at the first error rather than continuing the operation despite errors.

What are the various errors for which this option works?

I have tested it for the following error conditions:

  1. Stopped the mongod instance. I get following error indicating it lost connection with the mongodb.

    assertion: 10276 DBClientBase::findN: transport error: 127.0.0.1:15055 ns: admin.$cmd query: { getlasterror: 1 }
    
  2. Imported the same file again to same db and collection. This should give me duplicate entry error. Although, the error is displayed, import is not halted.

    Mon Jul 15 16:28:40.652 E11000 duplicate key error index: users.contacts_2.$_id_  dup key: { : "xexjiroiqcwujiuxrmedntmxhalniwygdyplrfvkjvfugdvxpadfvpferqtaquht" }
    Mon Jul 15 16:28:40.652 check 9 11
    Mon Jul 15 16:28:40.652 E11000 duplicate key error index: users.contacts_2.$_id_  dup key: { : "uyioegyqcenijjickljgdpmvihvyefvyfenjkmcptqafalhmwrvbjkwrtutybpxg" }
    Mon Jul 15 16:28:40.652 imported 10 objects
    

Now, i am confused. Does stopOnError works just for network errors or also for write error? Is there any way we can set write concerns or get the getLastError status while using mongoimport?

有帮助吗?

解决方案

The stopOnError explicitly skips the duplicate key error as can be seen from the source at https://github.com/mongodb/mongo/blob/master/src/mongo/tools/import.cpp#L314. I have filed https://jira.mongodb.org/browse/DOCS-1709 to have the documentation specify this.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top