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

Push document as child and update timestamp in parent document

I have a document as following: { "_id": ObjectId("507f191e810c19729de860ea"), "updateTimestamp": Date(1234567), "actions": [ { "timestamp": Date(123456) "action": "FIRE" }, { …
Akke
  • 3
  • 1
0
votes
1 answer

mongodb update multiple Array elements using db.update()

I compiled 2 update queries by referring to related stackoverflow answers, however, it doesn't seem to work, query updates all elements while only elements matching the criteria are expected to update. Document: [ { "_id": 259, "members":…
javapedia.net
  • 2,531
  • 4
  • 25
  • 50
0
votes
2 answers

Update nested property by condition in MongoEngine

I have MonogoDB collection described with following MongoEngine document: class Inner(EmbeddedDocument): value = StringField() class Outer(Document): inner = EmbeddedDocumentListField(Inner) So db.outer collection in MongoDB can look like…
Michal
  • 1,755
  • 3
  • 21
  • 53
0
votes
1 answer

MongoDB - Update multiple subdocuments in array in multiple documents

I'm making a node.js website. I have a posts collection in which comments for posts are stored in an array with the comment author's details as nested object. This is new post's schema: { "text": text, "image": image, "video": video, …
rawm
  • 251
  • 5
  • 24
0
votes
1 answer

How to update hours in data field in mongodb

I have set of mongo document, I need to convert/update the below values like ("workedDate" : ISODate("2020-07-01T00:00:00Z")) "workedDate" : ISODate("2020-07-01T20:03:04Z"), "workedDate" : ISODate("2020-07-01T19:59:07Z"), "workedDate" :…
0
votes
2 answers

$push and $set in same update query with condition $cond pymongo mongodb

I'm trying to update my collection For the single, object need to update the status and updated time. Input object id as id new status as current status Condition If the new status is different from the status in DB, then need to $push new status…
wulfnb
  • 111
  • 1
  • 11
0
votes
0 answers

How to speed up MongoDB data type change in a large collection?

We have a lot of strings stored where there should be Decimals. I'm trying to convert them using this. But its really slow. I feel like just getting a list of all the records to change and doing one giant update might be way faster? Am I doing…
0
votes
0 answers

How to push an object into a MongDB nested array based on a condition?

Suppose the MongoDB document(table) comment is _id:5ea7182e6dab0211980cbd57 AGREED_COUNT:[], BLOG_ID:"5ea572301ce15d34ac1d6d2a", USER_IMG_URL:"1587847821116-logo.jpg", USER_UUID:"5ea49d8cd6e3a73f48a433fd", …
0
votes
1 answer

MongoDB: Update outer array and nested arrays in single update

Document structure in cities collection is like this cities { _id: ObjectId("5e78ec62bb5b406776e92fac"), city_name: "Mumbai", ... ... subscriptions: [ { _id: 1, category: "Print Magazine", subscribers:…
Meena Chaudhary
  • 9,909
  • 16
  • 60
  • 94
0
votes
2 answers

How to update subset of a string in MongoDB?

I want to update the following subset of a string in monogdb Collection: Paper Field: URL Document Current: Name : House URL : www.home.com/300x300 Document Updated Name : House URL : www.home.com/600x600 I have already tried this but…
Kingswoop
  • 148
  • 8
0
votes
1 answer

How to find and update nested array element in an object on mongodb

I have a collection down below. I am trying to update an array element. I am trying to update if lineItem _id value is 1 then go to spec list and update characteristicsValue from 900 to 50 if specName is "Model", as you can see, _id is also an…
sakirow
  • 189
  • 1
  • 5
  • 18
0
votes
1 answer

Mongodb Dot Notation Not Updating Array

I'm having a problem with mongodb's dot notation for arrays. The 'bases' array in the user object has a set of bases in it which I'm trying to update via dot notation. To further complicate matters, I'm pushing the updates into an array of functions…
Brightstar
  • 315
  • 3
  • 18
0
votes
1 answer

MongoDB - Updating datatype in nested array for String to Number not working

I tried to update the MongoDB nested arrays data types, It's updated NaN value. Could you please help me out, anyone. Thanks MongoDB data: This is my MongoDB data productqtydetails collection. [{ "_id" : ObjectId("5d31567ea23d120f087a9ab1"), …
Senthil
  • 757
  • 2
  • 7
  • 25
0
votes
1 answer

Updating MongoDB nested array using same path as the search query

I have the following problem, I want to update a document with a path id.metadata.panels.items where panels is an array and items is an array. My search query looks at the items and displays only those that match the criteria of…
user3015289
  • 31
  • 1
  • 8
0
votes
0 answers

Mongo update new field with value from old field

What is the command to update a mongo collection. I have a variable id and key and the key is newly introduced. I want to update each document in the mongo collection by writing a new variable "key" that has the same value as "id" So far I…
Eric chen
  • 31
  • 6