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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T16:20:59+00:00 2026-06-14T16:20:59+00:00

{ teachers : [ {name: Lucy, id: 3, course: history}, {name: Mark, id: 6,

  • 0
{
 "teachers" : [
               {"name": "Lucy", "id": 3, course: "history"}, 
               {"name": "Mark", "id": 6, "course": "maths"}, 
               {"name": "Joan", "id": 20, course: "French"} 
               ] 
}

This document is in the “school” collection. I have been trying to access these imbedded documents using

db.school.find({teachers:{id:3}}) 

I also tried

db.school.find({teacher.id:3})

but I understand it isn’t working since mongo can’t look inside an embedded array.
Therefore I would like to turn these imbedded documents into individual documents. That is, remove the embedding and the “teachers” key, creating an individual document for each teacher.

The final “school” collection would be

{"name": "Lucy", "id": 3, "course": "history"}, 
{"name": "Mark", "id": 6, "course": "maths"}, 
{"name": "Joan", "id": 20, "course": "French"}

i would like to do it with python and save the new documents into a collection.

EDIT

this is what i have come up with for now:

import pymongo
import sys

connection = pymongo.Connection("mongodb://localhost", safe=True)

db = connection.hello
shows = db.school

for doc in db.school:
    for indiv in "teachers":
            try:
            db.individual.insert(indiv)
        except:
            print "Unexpected error", sys.exc_info()[0]
  • 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-14T16:21:00+00:00Added an answer on June 14, 2026 at 4:21 pm
    school_records = db.school.find()
    for i in school_records:
        for teacher in i['teachers']:
            db.individual.insert(teacher)
    

    What about this?

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

Sidebar

Related Questions

I have a MongoDb document like this schools: [ name : University, classes :
I am running a query: select course.course,iars.id, students.rollno, students.name as name, teachers.name as tname,
I have a class School and another class Teachers. now every school can contain
I have the following table where teachers class routine are stored Table Name: batchroutine_regular
I have two tables : teachers (teacher_id,teacher_name) courses (teacher_id,course_id) And I need to display
I am developing a webapp for teachers which may have hundreds of users who
I want to try display a relationship diagram. I have the xml <School> <Class>
I have a Reward System based on MySQL/PHP. Teachers award students points; students can
I have in my mysql databse 2 tables : 1.teacher(id(pk),name,phone,email) 2.student(id(pk),teacher'sid(FK),name,phone,email) The student table
I am working on an application that will have 2 kinds of users, teachers

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.