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 8972599
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T18:15:16+00:00 2026-06-15T18:15:16+00:00

I just start learning mongodb, and don’t know a lot yet. so my code:

  • 0

I just start learning mongodb, and don’t know a lot yet.

so my code:

#! /usr/bin/env python2.7

import pymongo
import datetime

class AccountsDB():
    def __init__(self):
        self.store_info()

    def store_info(self):
        try:
            conn = pymongo.Connection('localhost', 27017)
            db_name = 'accountsdb'
            coll_name = 'user_info'

            db = conn[db_name]
            coll = db[coll_name]

            print "Successfully connected to '%s'" % db_name

            for i in xrange(20):
                post = {
                    'f_name' : 'Sergey',
                    'l_name' : 'Ivanov',
                    'number' : '777-9-777',
                    'user_id': i
                }
                coll.insert(post)

            print "Done"
        except:
            print "Can't connect to the database"


if __name__ == "__main__":
    acc = AccountsDB()

and it gives me :

> db.user_info.find()
{ "_id" : ObjectId("50c64872bdbff34435192a94"), "l_name" : "Ivanov", "f_name" : "Sergey", "user_id" : 0, "number" : "777-9-777" }
{ "_id" : ObjectId("50c64872bdbff34435192a95"), "l_name" : "Ivanov", "f_name" : "Sergey", "user_id" : 1, "number" : "777-9-777" }
{ "_id" : ObjectId("50c64872bdbff34435192a96"), "l_name" : "Ivanov", "f_name" : "Sergey", "user_id" : 2, "number" : "777-9-777" }
{ "_id" : ObjectId("50c64872bdbff34435192a97"), "l_name" : "Ivanov", "f_name" : "Sergey", "user_id" : 3, "number" : "777-9-777" }
{ "_id" : ObjectId("50c64872bdbff34435192a98"), "l_name" : "Ivanov", "f_name" : "Sergey", "user_id" : 4, "number" : "777-9-777" }
{ "_id" : ObjectId("50c64872bdbff34435192a99"), "l_name" : "Ivanov", "f_name" : "Sergey", "user_id" : 5, "number" : "777-9-777" }

and so on....

But I want to get rid of ‘_id’ and use ‘user_id’ instead as my primary key. I’m pretty sure it can be done, but don’t know how.

  • 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-15T18:15:18+00:00Added an answer on June 15, 2026 at 6:15 pm

    I am pretty sure that the answer is no, you cant disable “_id”. why?
    just take a look to the source code of pymongo. Take a look to collection.py and search for “_id”.

    Mmm I think this could be done via monkey patching, but its to dark magic. just an idea and I dont recommend monkey patching at all. thats why my answer is no 🙁

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

Sidebar

Related Questions

I just start learning C++. When I execute my code it's jumping out of
I just start learning to write web services yesterday, kinda fascinating. I created an
I just start learning WPF, is that possible I can create an IE toolbar
I just start learning Python + Tornado for my web servers. Every time I
Just start to learning Cocos2d and getting errors in Xcode 4.3.3 (4E3002). Problem in
I just installed the latest SDK from Apple so I can start learning iPhone
hi i am a student and just start learning low level c programming.i tried
Just looking for some good reasons so i could start learning about them :/
I want to start learning OpenGL but I don't really want to have to
I just start learning Python in my company, I usually type python ext.py to

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.