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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T00:05:01+00:00 2026-06-02T00:05:01+00:00

I have this structure: public class User { public ObjectId Id { get; set;

  • 0

I have this structure:

public class User
{
    public ObjectId Id { get; set; }
    public Location Location { get; set; }
    public DateTime LastAround {get;set;}
}

public class Location
{
    public double Latitude { get; set; }
    public double Longitude { get; set; }
}

I’ve tried a few things but I want to update User’s Location and when they were last around.

Tried this:

userHelper.Collection.Update(
    Query.EQ("_id", userId),
    Update.SetWrapped<Location>("Location", new Location { Latitude = latitude, Longitude = longitude }).Set("LastAround", DateTime.UtcNow));

and this:

userHelper.Collection.Update(
    Query.EQ("_id", userId),
    Update.Set("Location.Latitude", latitude)
        .Set("Location.Longitude", longitude)
        .Set("LastAround", DateTime.UtcNow));

Nothing worked…how can I do this?

Update 4/17:

userHelper.Collection.Update(
                Query.EQ("_id", new ObjectId(userId)),
                Update
                    .SetWrapped<Location>("Location", new Location { Longitude = longitude, Latitude = latitude })
                    .Set("LastAround", DateTime.UtcNow)
            );

The lng and lat value orders seem to be very important when doing queries on them. I was doing a geonear query and getting an strange out of bounds error. If you update in the wrong order it will put lats first and then you get the error.

  • 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-02T00:05:02+00:00Added an answer on June 2, 2026 at 12:05 am

    Both of your original Update statements should work. I wrote a small sample program to demonstrate.

    After executing this Insert statement:

    var userId = ObjectId.GenerateNewId();
    var user = new User
    {
        Id = userId,
        Location = new Location { Latitude = 1.0, Longitude = 2.0 },
        LastAround = new DateTime(2012, 4, 14, 0, 0, 0, DateTimeKind.Utc)
    };
    collection.Insert(user);
    

    The document looks like this in the mongo shell:

    > db.test.find()
    { "_id" : ObjectId("4f8c5d33e447ad34b8c7ac84"), "Location" : { "Latitude" : 1, "Longitude" : 2 }, "LastAround" : ISODate("2012-04-14T00:00:00Z") }
    >
    

    After executing the first form of the Update statement:

    collection.Update(
        Query.EQ("_id", userId),
        Update
            .SetWrapped<Location>("Location", new Location { Latitude = 3.0, Longitude = 4.0 })
            .Set("LastAround", new DateTime(2012, 4, 15, 0, 0, 0, DateTimeKind.Utc)));
    

    the document looks like this:

    > db.test.find()
    { "_id" : ObjectId("4f8c5d33e447ad34b8c7ac84"), "Location" : { "Latitude" : 3, "Longitude" : 4 }, "LastAround" : ISODate("2012-04-15T00:00:00Z") }
    >
    

    And after executing the second form of the Update statement:

    collection.Update(
        Query.EQ("_id", userId),
        Update
            .Set("Location.Latitude", 5.0)
            .Set("Location.Longitude", 6.0)
            .Set("LastAround", new DateTime(2012, 4, 16, 0, 0, 0, DateTimeKind.Utc)));
    

    the document looks like this:

    > db.test.find()
    { "_id" : ObjectId("4f8c5d33e447ad34b8c7ac84"), "Location" : { "Latitude" : 5, "Longitude" : 6 }, "LastAround" : ISODate("2012-04-16T00:00:00Z") }
    >
    

    So the two forms of the Update statement are working.

    The full program is here:

    http://www.pastie.org/3799469

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

Sidebar

Related Questions

I have this structure of classes: public class L3Message { public int Number {
I have a structure similar to this: class OuterClass{ AnimatorListener sth; public OuterClass(){ sth
This is the common structure of all of my classes: public class User {
I have a class with this structure: public class BusinessObject { public int Column5
I'm developing a class and I have this structure: class userInfo { public $interval
I have classes structured like this: Public MustInherit Class A ' several properties End
Let's say I have data structures that're something like this: Public Class AttendenceRecord Public
I have this structure on form, <input type=test value= id=username /> <span class=input-value>John Smith</span>
Suppose i have this structure of elements: <div class=parent> <div class=something1> <div class=something2> <div
I have this HTML structure (excerpt): <td> <select id=test1 class=pub_chooser> <option value=99>All Publications</option> <option

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.