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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T10:47:05+00:00 2026-06-04T10:47:05+00:00

I have a document collection like this: { _id : ObjectId(4fb21439f31dfd122ce39c4a), Name : Freelander

  • 0

I have a document collection like this:

{
    "_id" : ObjectId("4fb21439f31dfd122ce39c4a"),
    "Name" : "Freelander 2",
    "Manufacture" : "Landrover"
}

I am using the C# driver, and want to check whether the “Name” field exists; if it does not, I need to update it from the code. Can someone help on this? Please share sample code because I am a newbie to mongoDB.

  • 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-04T10:47:06+00:00Added an answer on June 4, 2026 at 10:47 am

    You can use the exists operator:

    db.myCollection.find( { Name: { $exists: true } } );
    

    Using the C# driver, the equivalent would be something like this:

    IMongoQuery query = Query.Exists("Name", true)
    var results = myCollection.Find(query);
    

    To set a value if it doesn’t exist, you can use an Update statement like this:

    IMongoQuery query = Query.Exists("name", true);
    IMongoUpdate update = Update.Set("Name", "newvalue");
    myCollection.Update(query, update);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have one document in my params collection like this: { _id: ObjectId(4d124cef3ffcf6f410000037), code:
I have user document collection like this: User { id:001 name:John, age:30, friends:[userId1,userId2,userId3....] }
We have some embedded documents that look like this: { _id : ObjectId(4e402353bc9f6ec5a6000001), first_name
I have a schema, with a document structure that looks like this: { _id
I have a document, something like this: <root> <A node=1/> <B node=2/> <A node=3/>
I have a geo collection that contains items like: [state name] [city], [state] [country]
Suppose I have a collection with some set of documents. something like this. {
I have a MongoDB collection called employees where there are documents like this: {
I have a Grails 1.3.7 domain class that is declared like this: class Document
I have many collections of documents in a mongo database that look like this:

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.