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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T15:07:08+00:00 2026-06-13T15:07:08+00:00

Using PHP and MongoDB, i have a collection called users and another one called

  • 0

Using PHP and MongoDB, i have a collection called users and another one called forms in the same DB.

I am using the Mongodb ObjectID as user identifier for the documents in the forms collection, saving the users ObjectId as uid on each forms document.

I am going to create an index of the uid field in the forms collection, but my question is how i should save the users Objectid?

As of now I am saving it as a normal string like (simplified)

$collection->insert( array('formName'=>'The name','uid'=>'CURRENT_USERS_ObjectId_AS_string') );

Does this seem logic or is best practice in this case to create a Mongodb ObjectID for uid like

$collection->insert( array('formName'=>'The name','uid'=> new MongoId('CURRENT_USERS_ObjectId_AS_string')) );
  • 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-13T15:07:09+00:00Added an answer on June 13, 2026 at 3:07 pm

    Now I am not familiar with PHP but the schema design that you have suggested is good.I am using a similar structure for my c# implementation.Just to be clear here is a sample of my schema design

    Account Class
    
    public  ObjectId Id{get;set;}
    public   string  Email {get;set}
    public   string  Password{get;set;}
    
    User Class
    
     public ObjectId Id{get;set;} 
     public string  AccountId {get;set}//refers to the ID in the account.
    

    Now if I want to query an account for any user I can simply query it using the accountId in the user class.

    MongoDb calls this referencing technique as manual referencing and this is also the one that it recommends here is the link http://docs.mongodb.org/manual/applications/database-references/

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

Sidebar

Related Questions

I have a MongoDB collection of documents, each document representing a fish . Users
I am using the MongoDB PHP Library and have the following query array Array
I would love to sort an embedded MongoDB object using PHP Lithium. I have
I'm using MongoDB with PHP to store songs which users add via a basic
I have inserted and fetched data using MongoDB, in PHP. Is there an actual
I am using PHP Yii Framework with MongoDB(yiimongodbsuite). I have created a Model which
I'm using php sesions with mongodb by defining the session_set_save_handler() if every user has
I'm using MongoDB with PHP's own driver and I have saved multiple arrays under
So I'm building an app using PHP and MongoDB which will have a fair
I am using php 5.2 version and I have installed mongodb driver in zend

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.