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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T03:46:36+00:00 2026-06-03T03:46:36+00:00

I have a simple game with multiple rounds and I want to update the

  • 0

I have a simple game with multiple rounds and I want to update the most recent round:

class Game
{
    public ObjectId Id { get; set; }
    public List<Round> Rounds { get; set; }
}

class Round
{
    public int A { get; set; }
    public int B { get; set; }
}

How can I do the equivalent of games.Rounds.Last().A = x using the official MongoDB C# driver?

Edit: Added Round.B. Note that in this case, both A and B may be updated concurrently so I cannot save back the entire document. I only want to update the A field.

  • 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-03T03:46:37+00:00Added an answer on June 3, 2026 at 3:46 am

    If you’re using the drivers with LINQ support, then I suppose you could do this:

    var last = collection.AsQueryable<Game>().Last();
    last.A = x;
    collection.Save(last);
    

    I imagine it wouldn’t be as efficient as a hand-coded update statement, but this does functionally mirror your javascript version for the most part.

    Edit: Without LINQ, and doing a subset update

    var query = Query.EQ("_id", MongoDB.Bson.BsonValue.Create(games.Id);
    var update = Update.Set("Rounds." + games.Rounds.Length - 1 + ".A", MongoDB.Bson.BsonValue.Create(x));
    
    Collection.Update(query, update);
    

    Not so pretty looking, but you can index into an array by the number in Mongo, so you’d miss out on the case where a new Round was added to the game before you update.

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

Sidebar

Related Questions

I have a simple game activity. I start it and than press the back
I have a simple JavaScript game that sends a score to PHP by adding
Say I have simple program that emulates a board game with a number of
I'm writing a simple game and I'm going to have the mouse control the
I have a simple tank wars style game using the allegro open source library.
Trying to make simple minesweeper game in python, but have one problem. I have
I'm working on a simple board game in qt, and i have some problem
I'm creating a simple JavaScript multiple choice game. Here is a sample question: p
I have a simple game that uses a 3D grid representation, something like: Blocks
I have created a simple XNA Windows Class Library with XNA 4.0 called NivekGameEngine.

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.