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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T05:28:46+00:00 2026-06-02T05:28:46+00:00

How to replace third_id in this record (only one document needs to be updated)?

  • 0

How to replace third_id in this record (only one document needs to be updated)?

> db.collection.find( {"_id" : ObjectId("4f90cf0cd4bea011930001a3"), "first_id": ObjectId("4edf056800126757c000000f")}) { "second_id" : ObjectId("4f355e430012671d77000ec0"), "third_id" : ObjectId("4edf056800126757c000000f"), "note" : "blah-blah"}

Like this?

db.collection.update( { {"_id" : ObjectId("4f90cf0cd4bea011930001a3"), "third_id" : ObjectId("5edf056800126757c000000f")}, , true )

Tutorial says:
db.collection.update( criteria, objNew, upsert, multi )

Arguments:

criteria – query which selects the record to update;

objNew – updated object or $ operators (e.g., $inc) which manipulate the object

upsert – if this should be an “upsert” operation; that is, if the record(s) do not exist,
insert one. Upsert only inserts a single document.

multi – indicates if all documents matching criteria should be updated rather than just one. Can be useful with the $ operators below.

  • 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-02T05:28:47+00:00Added an answer on June 2, 2026 at 5:28 am

    Since you only want to update a single document and you aren’t trying to do an upsert and you don’t want to replace the whole document but just one field, you can do:

    db.collection.update( { {"_id" : ObjectId("4f90cf0cd4bea011930001a3"), 
                          { $set : {"third_id" : ObjectId("5edf056800126757c000000f") } } )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This question is related to this previous one on how to replace accented strings
How can one replace a part of a line with sed? The line DBSERVERNAME
Below code works well, its able to replace any tag it find with a
I've searched for an answer to this and I've come up with only two
I'd like to use JavaScript only (no jQuery) to replace an inline onmenuclick event
replace newline seems to be a question asked here and there like hundred times
replace(replace(Names,'Lara',''),'M','') is working, but declare @midname varchar set @midname = 'Lara' replace(replace(Names,@midname,''),'M','') is not
CamelCase.replace(/[A-Z]/g, $1) Produces >> $1amel $1ase How to replace all occurrence of camel cases.
How do you replace an element in jQuery and have the replacement element returned
I am trying to replace a two letter state abbreviation with text then the

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.