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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T22:22:33+00:00 2026-06-18T22:22:33+00:00

I have a collection called messages. Each message has a ‘read’ boolean value. In

  • 0

I have a collection called “messages”. Each message has a ‘read’ boolean value. In some instances when I retrieve the messages, I’d like to set the value to ‘true’, while returning the pre-modified value.

So, let’s say I have 1 message, whose ‘read’ value is ‘false’. When I retrieve it, I’d like to return the initial ‘false’ value, but in the same operation I’d like to set it to ‘true’.

Any way of doing that?

  • 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-18T22:22:34+00:00Added an answer on June 18, 2026 at 10:22 pm

    The findAndModify command is what you’re looking for:

    4 . The command returns the original unmodified document selected for this update.

    If you were using it in the Mongo shell, your usage would look like:

    db.messages.findAndModify({query: {read: false}, update: {read: true}})
    

    It looks like you’re using Java, though. The Java driver offers a few different signatures for findAndModify(). You can check them out in the javadoc for DBCollection.

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

Sidebar

Related Questions

I have a collection in MongoDB called CrawlUser. It has a list called CrawlStatuses,
So, I have a collection called: 'members' and in that I have a user
We have installed TFS 2010 RC. By default it creates a project collection called
We have a collection of entities of type called Unit , collection of entities
I have Collection List<Car> . How to compare each item from this collection with
I'm planning to have collection of items stored in a TCollection. Each item will
for example I have collection foo of documents like that: {tag_cloud:[{value:games, count:10}, {value:girls, count:500}]}
I have a message system where I want different message handlers to be called
I have a model called Metadatum (silly, I know) which has two fields, key
I have a model called Project, which is a collection of information stored by

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.