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

  • Home
  • SEARCH
  • 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 8296831
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T15:10:15+00:00 2026-06-08T15:10:15+00:00

We have a User doc in Mongo DB and want to use the _id

  • 0

We have a User doc in Mongo DB and want to use the _id field as the userID field and increment it.
i found a counter(“user”) JS method in Mongo docs (http://www.mongodb.org/display/DOCS/Object+IDs).

From the Mongo Shell, i can invoke,

db.user.insert({_id:counter(“user”), name:”tom”…});

Now, how can i use the same command from Java code? Not able to find a way to specify the Javascript function from Java code.
Also saw the findAndModify Command and usage of $inc, but not able to get it to work. This way we can do without invoking the JS counter func, i presume.

What are the implications of using custom value in the _id field instead of the Mongo’s Object Id, any caveats?
~vish

  • 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-08T15:10:17+00:00Added an answer on June 8, 2026 at 3:10 pm

    TL;DR: Just use ObjectIds

    It makes little sense to generate new ObjectIds like that. You should just create a new ObjectId for each new object. It’s easy and offers good global uniqueness guarantees.

    If you’re doing this to abstract yourself from the database, it won’t work. MongoDB is a very specific database. Abstraction is possible if you only use mongo as a K/V store (think memcached, but slower), but there are better products with this functionality.

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

Sidebar

Related Questions

I have created a C# user control which I want to use in VB.NET
i have user control, which i render on several views. i want to show
Let's say I have User model and Post model. Post model contains field user_id
I have a script that lets the user upload text files (PDF or doc)
So I'm trying to both dynamically create a .doc file and have the user
As per http://help.eclipse.org/helios/topic/org.eclipse.jst.ws.cxf.doc.user/reference/preferences.html The CXF 2.x preferences can be accessed via Window > Preferences...
After following instructions from orbeons wiki From: http://wiki.orbeon.com/forms/doc/user-guide/form-builder-user-guide#TOC-Creating-a-PDF-template-for-use-wit Non-exclusive checkboxes Use PDF checkboxes Use
Ex: Following is my current document. http://www.youtube.com/watch?v=cgxJHBJ_X-g&feature=related I have a User Script and the
I have an xml document as follows <users> <user test=oldvalue> <userid>sony</userid> <name>vijay</name> </user> </users>
I have files like .doc .pdf .excel... and i want to open them externally.

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.