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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T07:52:12+00:00 2026-06-04T07:52:12+00:00

I have objects with 3 string fields Country, Province, City. They can contain null

  • 0

I have objects with 3 string fields Country, Province, City. They can contain null or some string name.

I wanna query all data with the exact same values.

For Example i need all data where

City = null,
Province = "WA",
Country = "USA"

I created BsonDocument:

var lookup = new QueryDocument
{
    {"GeoPosition.City", userLocation.City},
    {"GeoPosition.Province", userLocation.Province},
    {"GeoPosition.Country", userLocation.Country}
};

But null field was thrown away and document looks like:

{
    "GeoPosition.Province" : "WA",
    "GeoPosition.Country" : "USA"
}

If i’m triing to use

Query.EQ("GeoPosition.City", userLocation.City)

I have exception saying that parametr cant be null.

As i see in documentation there is no problem in building query cheking if value equals null. So that is a problem with C# driver. Any ideas how to solve this problem?

  • 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-04T07:52:14+00:00Added an answer on June 4, 2026 at 7:52 am

    Depends on the data type of your city variable. If the city variable is of type BsonValue you can use the ?? operator directly:

    BsonValue city = null;
    var query = Query.EQ("city", city ?? BsonNull.Value);
    Console.WriteLine(query.ToJson());
    

    If your city variable is of type string you need an extra conversion cast to make the compiler happy:

    string city = null;
    var query = Query.EQ("city", (BsonValue)city ?? BsonNull.Value);
    Console.WriteLine(query.ToJson());
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Assume you have some objects which have several fields they can be compared by:
I have filled List<Object1> Object 1 contain 2 fields (int id & string name)
i have an array of Tag objects class Tag { public string Name; public
I have a database which contains some string fields with only whitespace in them.
I have a model object called Country : class Country { public string Name
I have several thousand objects with a string property in the format of yyyy-MM-ddTHH:mm:ssZ
I have JSON string that has nested objects with dynamic names that vary each
I have a string and a list of objects: gpl = %(id)s : %(atr)s
I have a simple json string which contains a collection of objects http://sandapps.com/InAppAds/ads.json.txt When
Let's say we have a collection of Person objects class Person { public string

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.