mongodb dataypes when importing

202 views Asked by At

I want to clone a collection to a new collection, remove all the documents, and then import new documents from a csv file. When I do the copy using copyTo everything works fine. The datatypes are copied over from the source collection to the new collection. However, after I remove all the documents from the new collection and import from the csv, the datatypes are lost. The datatypes from my source csv are already setup to match what is in the source collection I copied from.

  • Is there a way to preserve the datatypes after removing all documents from a collection?
  • How can I copy the datatypes from my csv when importing? For example my date columns show as string.
1

There are 1 answers

4
Paul On BEST ANSWER

A new collection doesn't have a fixed schema so documents added don't have to be similar unless you've created the collection using the validator option. You can also add validation to an existing collection. See Document Validation in the MongoDB manual.