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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T03:41:08+00:00 2026-05-27T03:41:08+00:00

Given this doc form a collection of Courses I would like to pick a

  • 0

Given this doc form a collection of Courses I would like to pick a
single participant object from the embedded array

{
    _id: someCourseId,
    CourseName: "someName",
    Participants[
        {UserId: X Name: "person1"},
        {UserId:Y, Name:"person2"},
        {UserID:Z, Name:"person3"}
    ]
}

How do I write a query with the official C# sharp driver that only
returns the embedded array Element with userID Y ?

Right now I can select the Courses having a Participant with id Y
using Query.EQ(“Participants.UserId”,Y) and I can select to only get
the Participants field of the Course object using
SetFields(“Participants”), but if this array is huge, I don’t want to
fetch an entire array, but only a single element. Is this possible?

If not, then I would consider it best practice to not use embedded
arrays in cases where fetching specific elements are required.
Instead a separate collection should be used to hold the array values
and a “foreign key to the root doc” (like you would do in a RDBMS).
That is, in my example I would create a Participants collection, where
each doc holds the id of a Course. Do you agree?

  • 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-27T03:41:09+00:00Added an answer on May 27, 2026 at 3:41 am

    You can use slice like this:

     // it will skip 0 elements and load only one element from nested array
     var slice = Fields.Slice("Participants", 0, 1); 
    

    Also, i guess you know that mongodb always return root document, but you can change content of this documents by specifying fields you want load and size of nested array.

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

Sidebar

Related Questions

Given an XML document like this: <!DOCTYPE doc SYSTEM 'http://www.blabla.com/mydoc.dtd'> <author>john</author> <doc> <title>&title;</title> </doc>
This is copied ditto from example given in Sql2008 R2 doc - Syntax: DATENAME
I'm parsing a JSON response via $.ajax() and building a form from this object's
Given this example XML file: <doc> <tag> Hello ! </tag> <tag> My name is
In gcc doc one reason is given for using section . This reason is
Given this object class Contact { public IEnumerable<Person> People { get; } public string
Given this XML ... <ListBucketResult xmlns=http://s3.amazonaws.com/doc/2006-03-01/> <Name>public.rpmware.com</Name> <Prefix></Prefix> <Marker></Marker> <MaxKeys>1000</MaxKeys> <IsTruncated>false</IsTruncated> <Contents> <Key>0.dir</Key> <LastModified>2008-06-25T16:09:49.000Z</LastModified>
Given the hpricot xml at the bottom of this post, how would I select
Given this document: <doc> <element> <list> <key attr='val'/> </list> </element> <element> <list> <key attr='other'/>
I would like to parse a document using SAX, and create a subdocument from

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.