Questions tagged [mongodb-update]

Modifies an existing document or documents in a collection.

The method can modify specific fields of an existing document or documents or replace an existing document entirely, depending on the update parameter.

By default, the update() method updates a single document. Set the Multi Parameter to update all documents that match the query criteria.

The update() method has the following form:

db.collection.update(
   <query>,
   <update>,
   {
     upsert: <boolean>,
     multi: <boolean>,
     writeConcern: <document>
   }
)

Source

195 questions
0
votes
1 answer

MongoDB - Update an array of documents with two levels deep which matches conditionals from different levels

What I need to do is only update the availableWeights field if the event id and weight match what I pass in (ObjectId("67823649279") & 0) and the userId field is "empty" exactly. I will replace the empty fields with { userId: ObjectId(), name:…
Wayne
  • 660
  • 6
  • 16
0
votes
1 answer

Problem using updateOne in an array with mongoose

currently making an e-commerce application and trying to make the checkout api that will credit multiple stores with their respective amounts due. I'm sure the logic works because the history can be created properly but it appears the problem with…
0
votes
0 answers

MongoDB $unset: "Executing this update would put you over your space quota"

I have a collection containing Reddit comments, gathered by a bot. The schema looks like this: { _id: ObjectId, author: string, body: string, permalink: string, created_utc: number, upvotes: number, downvotes: number } I…
0
votes
1 answer

MongoDB - Update the value of one field with the value of another nested field

I am trying to run a MongoDB query to update the value of one field with the value of another nested field. I have the following document: { "name": "name", "address": "address", "times": 10, "snapshots": [ { "dayTotal": 2, …
Gentle Song
  • 90
  • 1
  • 7
0
votes
1 answer

MongoDB .NET Driver - Update Item in Set

I've got this entity: internal record OrderBookEntity { [BsonId] public required AssetDefinition UnderlyingAsset { get; init; } public required List Orders { get; init; } } which leads to this sort of document: { …
0
votes
0 answers

Embedded vs. Referenced Documents mongoDB

I'm starting to study mongodb, but I want to understand better when to use embedded or referenced documents. the project I'm trying to make is something similar to a POS (point of sale), working like: Every time that someone make a purchase, it…
0
votes
1 answer

Update document where all items in an array has the same value

I am making a migration script where I need to update a status value on all documents where the items in an array has the same value Data structure [ { _id: 'asdasd', status: 'active', approvers: [ {status: 'approved'}, {status:…
0
votes
1 answer

MongoDB - How to replace only one object from array

I have the following BSON data in MongoDB: [ { partyName : "p1", poNumber : "789", }, { partyName : "p2", poNumber : "700", }, { partyName : "p3", poNumber : "889", } ] I want to replace the object where…
gaurav joshi
  • 77
  • 1
  • 8
0
votes
0 answers

How to speedup the update query to mongoDB from pandas dataframe

#Updating records in mongoDB from pandas dataframe# #The updating 500000 records is taking more than a day# from pymongo import MongoClient import pymongo import pandas as pd import json from pandas.io.json import json_normalize from datetime import…
eshwar raj
  • 11
  • 1
  • 3
0
votes
1 answer

MongoDB - Add new property to each object in an array property for each document

I have the following collection in MongoDB: // document 1 { elements:[ { prop1:true, prop2:false, }, { prop1:true, prop2:false, } ] }, // document 2 { elements:[ { prop1:true, …
bssyy78
  • 319
  • 5
  • 16
0
votes
1 answer

MongoDB Java - UpdateMany() with both an $inc operator and $concat aggregation

JavaVersion: 11 --- MongoDB-driver: 4.6.1 I'm wondering if it is possible to implement a bulk update method that would increment the document version through the $inc operator while simultaneously making it possible to concatenate a string to a…
0
votes
1 answer

Isn't it possible to concat new value to a field in MongoDB document while updating it?

I have few documents in a MongoDB Collection and each has a unique field called "requestid". Now I need to update a field "requeststatus" by concatenating a new value to an existing one in NodeJS application. I started using MongoDB for very recent…
shary.sharath
  • 649
  • 2
  • 14
  • 29
0
votes
1 answer

MongoDB - How to update a single object in the array of objects inside a document

I have the following document structure: { "Agencies": [ { "name": "tcs", "id": "1", "AgencyUser": [ { "UserName": "ABC", "Code": "ABC40", "Link": "http.ios.com", …
0
votes
1 answer

MongoDB .NET Driver - Increment a value inside dictionary

I need to increment a value that is stored inside a dictionary, the structure of my object is (basically) the following: public class OrderDetails : EntityBase { public int OrderId { get; set; } public Dictionary TotalViewsPerUser…
0
votes
1 answer

MongoDB - How to use arrayFilters in pipeline-style for update

I use Mongo 4.4 and I try to perform an update with the aggregation pipeline using updateOne that updates the nested array elements. In order to update the specific array member I use an arrayFilter in the option but for some reason, I get the error…