Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

89
Views
mongoimport rejects NumberDecimal types

Mongodb from v.3.4 supports NumberDecimal

I have MongoDB server version: 3.4.1, but when I execute mongoimport shell command I get an error:

Failed: error processing document #7: invalid character 'D' in literal NumberInt or NumberLong (expecting 'I' or 'L')


My json:

{"c":"7E474601-B511-4AD9-B2B8-7E61807F9673","n":"n1","v":NumberDecimal("95")}

Normal insert executes ok, so this is mongoimort problem.

db.aaa.insert({"c":"7E474601-B511-4AD9-B2B8-7E61807F9673","n":"n1","v":NumberDecimal("95")})
WriteResult({ "nInserted" : 1 })

Why is that? Can you help me?

over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

One trick to figure out the correct extended json format is to use the mongoexport utility on a collection to see how MongoDB itself publishes the json out.

In this case the following should work:

{"c":"7E474601-B511-4AD9-B2B8-7E61807F9673","n":"n1","v":{"$numberDecimal":"95"}}

I tested this with mongoimport with server version 3.4.1 and it imports the numberDecimal correctly.

over 4 years ago · Santiago Trujillo Report

0

NumberDecimal("95") is not a valid JSON representation. It should be

{"c":"7E474601-B511-4AD9-B2B8-7E61807F9673","n":"n1","v":95}

It works with mongo shell because the shell is a javascript interpreter that treats NumberDecimal as a valid data type.

If you need NumberDecimal data type you need to use a driver or the mongo shell.

Form a bash shell you can run this simple script:

for i in `cat aaa.json`
do
 mongo --quiet --eval "db.aaa.insert($i)"
done

Please note that this is row by row insertion and not very efficient.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!