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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T22:24:03+00:00 2026-05-29T22:24:03+00:00

I use mongo, and I have a little problem here. I want to get

  • 0

I use mongo, and I have a little problem here. I want to get a record, but I just have the id of an array list inside record. This is what my data looks like.

{    
   "_id": ObjectId("1113000001"),    
   "menu": "desertsunday",   
  "fruit": {
      "0": ObjectId("102b000000"),
      "1": ObjectId("5200000000"),
      "2": ObjectId("2900000000"),
      "3": ObjectId("9870000002")   } 
 }

I just have 102b000000 for get the record, I need to get the menu from there but I can’t get it with standard mongo. Can anybody help me ?

  • 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-05-29T22:24:05+00:00Added an answer on May 29, 2026 at 10:24 pm

    Actually fruit in you schema is not array, it is list of objects, because of this there is only one way to get root document by one fruit id:

    db.items.find({"fruit.0": ObjectId("102b000000")}) 
    

    In above query you should know ordinal number of fruit to fetch root document.

    But if you can redesign your database as follows:

    {    
       "_id": ObjectId("1113000001"),    
       "menu": "desertsunday",   
       "fruit": [
          { i:0, id: ObjectId("102b000000") },
          { i:1, id: ObjectId("5200000000") }
        ]
    }
    

    you can easy fetch root doc by embedded array item id:

    db.items.find({"fruit.id": ObjectId("102b000000")}) 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to use a capped collection in Mongo, but I don't want my
For the project we have a MySQL database. We want to use Mongo'S GridFS
We have a User doc in Mongo DB and want to use the _id
I need to use the mongo-storm library and Clojars doesn't have it . So
I've been trying to use mongo with some data imported, but I'm not able
I'm working on a scheme that will heavily use array fields in mongo documents,
Lets say I have mongo documents like this: Question 1 { answers:[ {content: 'answer1'},
I don't have any prior experience with database, but I have to use it
I have an application where I'd like to use a NoSQL database, but I
in mysql i use JOIN and one query is no problem. what about mongo?

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.