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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T15:01:05+00:00 2026-06-06T15:01:05+00:00

This is the format of my document: { _id: some id, name: ‘some name’,

  • 0

This is the format of my document:

{
    _id: some id,
    name: 'some name',
    versions: []
}

In the versions field I store objects like {v: '2.5', count: 5} where count holds the number of times a version is in used.

What is the simplest way to do the following?

  1. Insert a new object inside the versions array if it doesn’t exist
  2. Ff a particular version exists inside the versions array then increment its count
  • 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-06T15:01:06+00:00Added an answer on June 6, 2026 at 3:01 pm

    Simplest way being should be,

    db.collection.update({versions.v:'some_version'},{"$inc":{"versions.$.count":1}});
    

    This will increment your count if version is exist, but as MongoDB documentation says, $ operator cannot be mixed with upsert, so above query won’t result in insert if {versions.v:'some_version'} fails.

    The positional operator cannot be combined with an upsert since it
    requires a matching array element. If your update results in an insert
    then the “$” will literally be used as the field name.

    Below are JIRA tickets for supporting upsert with $. You can vote and watch these issue.

    Upsert with $-positional operator can create bad documents

    Support $ positional operator with an upsert

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

Sidebar

Related Questions

I have text like this format term: 156^^^:^^59 datainput Or term: 156^^^:59 datainput or
I have data in Oracle table like this format Gname, PBOOK, CNIC, LPNAME, ACRE
My xslt transform does not pick up my document, this is because some/most elements
I have dates in this format in my database 01-APR-12 and the column is
I'm using this format in my htaccess to redirect several pages/links: RewriteEngine On RewriteRule
I have date in this format (YYYYMM): 201201 // Gen, 2012 201202 // Feb,
I have Date in this format (2012-11-17T00:00:00.000-05:00). I need to convert the date into
In DataTable i have this format mm/dd/yyyy hh:mm:ss AM I want to change format
How to see this format hh:mm from hh:mm:ss in SQL Server 2008 query ?
I have data in this format coming from a database... BUS 101S Business and

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.