Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8155059
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T16:33:28+00:00 2026-06-06T16:33:28+00:00

I have a collection in mongo in which I am inserting data from Perl

  • 0

I have a collection in mongo in which I am inserting data from Perl (using MongoDb) and with mongoinsert. The problem is that the data types for numbers become inconsistent.

For example, from Perl, I do:

$collection->insert({ _id => 1, value => "record 1" });

and I have a JSON file that I import with mongoimport, that contains this line:

{"_id":2,"value":"record 2"}

Now, if I do a search on the collection, I get the following:

> db.test.find()
{ "_id" : NumberLong(1), "value" : "record 1" }
{ "_id" : 2, "value" : "record 2" }

Is there a way to force the Perl driver to insert the _id as a 32-bit number? or to force mongoimport, to write it as a 64-bit (NumberLong)?

Would you have other suggestions on how to keep the _id field consistent?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T16:33:30+00:00Added an answer on June 6, 2026 at 4:33 pm

    The MongoDB Perl module documentation has some information on 64-bit integers:
    http://search.cpan.org/dist/MongoDB/lib/MongoDB/DataTypes.pod#64-bit_Platforms

    The integer size difference is dependent on the language and driver you are using; dynamically typed languages like Perl, PHP, and Python will use 64-bit integers if compiled for 64-bit, and 32-bit integers if compiled for 32-bit. Statically typed languages like Java may be more specific (Int is always 32-bit) but some languages, like C, only guarantee that an int is at least 16-bits (and a long is bigger than an int and at least 32-bits).

    The NumberLong _ids you are seeing in the shell query are expected because you are inserting data using 64-bit Perl (which uses 64-bit integers). The 32-bit integers are actually in NumberInt format, but the shell doesn’t explicitly display the type for these.

    As far as indexing and querying applies, numeric _ids will still need to be unique.

    For example, trying to insert the same integer _id as both 32 and 64 bit will cause a duplicate key error:

    MongoDB shell version: 2.0.6
    >     db.ints.insert({ _id: NumberInt(1) });
    >     db.ints.insert({ _id: NumberLong(1) });
    E11000 duplicate key error index: testing.ints.$_id_  dup key: { : 1 }
    

    Similarily, when querying the numeric _ids will match:

    >     db.ints.insert({ _id: NumberLong(2) });
    >     db.ints.find({_id:Number(2)});
    { "_id" : NumberLong(2) }
    
    >     db.ints.insert({ _id: NumberLong(3) });
    >     db.ints.find({_id:Number(3)});
    { "_id" : NumberLong(3) }
    

    If you’re concerned about the difference in integer sizes using different drivers or commands such as mongoimport, you could write your own import script. The equivalent of mongoimport could quickly be put together using Text::CSV_XS.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a simple mongodb collection which stores tweets directly from the twitter api
I have a Mongo collection that simply references an ID to another collection. Hypothetically
I'd like to query a mongo collection for records which either don't have a
This is the first project by me which is using MongoDB. I have hosted
I have a Mongo collection called documents which has the following structure: { name:
I have a mongo collection which has documents with two fields fieldA and fieldB,
If I have data in my users collection that looks like: { name: '...',
I have a collection in mongo which has name and count fields. {name:'myName',count:5} Is
I have many collections of documents in a mongo database that look like this:
In Mongo my understanding is that you can have databases and collections. I'm working

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.