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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T08:50:13+00:00 2026-06-17T08:50:13+00:00

In Monger there is a insert-and-return function for returning a newly inserted document. There

  • 0

In Monger there is a insert-and-return function for returning a newly inserted document.

There is no update-and-return function.

How can I return an updated document from the function that executes the update?

I think I could use save-and-return but it seems to me that I am not able to use operators like $push with this function.

  • 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-17T08:50:13+00:00Added an answer on June 17, 2026 at 8:50 am

    I can see two options for you.

    First option is to use JohnnyHK’s solution with find-and-modify function:

    (mc/find-and-modify "users"
      (select-keys my-doc [:_id])
      { $push { :awards { :award "IBM Fellow"
                          :year  1963
                          :by    "IBM" }}}
      :return-new true)
    

    Second option is to use save instead of update. It’s a good choice if you already have the entire document loaded from mongodb. You can easily replace mongodb operators like $push with clojure functions like update-in. Manipulation with clojure maps seems for me as better approach. If you have problems with finding clojure alternatives for mongodb operators I can help you.

    For my previous example it will look like this:

    (mc/save-and-return "users"
      (update-in my-doc [:awards] conj
        { :award "IBM Fellow"
          :year  1963
          :by    "IBM" }))
    

    Myself, I prefer this way, because it looks more Clojure-ish.

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

Sidebar

Related Questions

I'm trying to create a custom function that I can place in a queryset
I have some integrtion tests that create an HSQL db from JPA entities. This
I am trying to get a Ajax-call made from jQuery to return a JavaScript
I have created an app where a user can insert various subjects and their
String myQuery1 = insert into mytable(mycol) values(myval) \ngo; String myQuery2 = insert into mytable(mycol)
I would like to add notification center from a cpp class, is it possible????
How would I pretty print the output from the cmd.exe shell command path so
Here is an example view named MANVW : SELECT manager_id, manager_sign FROM ( SELECT
I have a self-referencing many-to-many relationship between users and managers that looks like this:
I have noticed that executing a dbStats command returns an incorrect number of collections.

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.