Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

377
Vistas
mongoimport fails to load $uuid field from a JSON file

I want to use mongoimport to load a JSON file that includes UUIDs fields.

A program that creates JSON files serialise UUIDS like this:

{ "_id": {"$uuid": "9ab62b5e-f34a-3854-b8bf-df7ee0102229"}, "foo": "bar" }

In the collection to which I want to import the document UUID is represented in the binary format:

{ "_id" : BinData(3,"eT/WZXnp96m5uHOpApFSmg=="), "foo" : "bar"}

mongoimport doesn't like the $uuid bit, and fails with

$ cat foo.json|  mongoimport -h 127.0.0.1 -d mydb --collection mycollection
2017-01-30T23:46:05.060+0100    connected to: 127.0.0.1
2017-01-30T23:46:05.079+0100    error inserting documents: $uuid is not valid for storage.
2017-01-30T23:46:05.079+0100    imported 0 documents

Any ideas how could I get around this problem

over 4 years ago · Santiago Trujillo
2 Respuestas
Responde la pregunta

0

According to mongoimport documentation

Warning

Avoid using mongoimport and mongoexport for full instance production backups. They do not reliably preserve all rich BSON data types, because JSON can only represent a subset of the types supported by BSON. Use mongodump and mongorestore as described in MongoDB Backup Methods for this kind of functionality.

So understandably that UUID turned binary data doesn't come under valid JSON data types hence it fails, you can try mongodump it's more robust.

over 4 years ago · Santiago Trujillo Denunciar

0

I went out and decided to write a script that converts $uuid to $binary that seems to be accepted by mongoimport and the records are properly inserted into mongodb.

this is how I use it:

cat exported.json | uuid_to_bindata.rb | mongoimport -h 127.0.0.1 -d mydb --collection mycollection

This is the uuid_to_bindata.rb script.

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda