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 setting a key in every object of an array

I want to make sure only ONE item in an array is marked as "current". So my thinking is that IF the incoming data is marked "current = true" then I want to change ALL the other items to "current = false". the data looks like this: { _id:123, …
j-p
  • 3,698
  • 9
  • 50
  • 93
0
votes
1 answer

How can i update the product quantity in cart?

My cart schema var CartSchema = new mongoose.Schema({ product: { type: mongoose.Schema.Types.ObjectId, ref: 'Product' }, totalQty: { type: Number, default: 0 }, totalPrice: { type: Number, …
Sagar Pednekar
  • 334
  • 4
  • 14
0
votes
0 answers

Mongo document to enforce strict datatype using bsons

I have a codebase in which we have widely been using Bson document to persist / update documents in multiple collections. Whilst mongodb gives us the flexibility to add attributes and extend as required, we want a specific attribute in a collection…
0
votes
0 answers

mongoDB: is it better to remove a field to nullify it?

I would like to know which is better for an existing document: To remove a field to nullify it, or to keep the field and simply set it to null? I'd also like to know more about the process of saving the document: Will the document be saved in the…
zeus
  • 12,173
  • 9
  • 63
  • 184
0
votes
1 answer

Mongodb insert object into an array which is inside another attribute

I need to update a document by inserting a bid into the Bid array which is part of Bid. An example document is below: { "_id" : "1044300051", "Bids" : { "Bid" : [ { "Bidder" : { "_id" : "pickford25", …
Roc47HS
  • 71
  • 1
  • 12
0
votes
1 answer

Updating an attribute in MongoDB

I am trying to update an attribute of a field. For example, updating the name "Orchid garden" to a new name, let's say, "The Beautiful Garden"... I am following the syntax given in the MongoDB Documentation but it seems that I am missing something.…
0
votes
2 answers

Why i am getting an error code 10003 while updating documents in mongodb? I'm using mongodb version 3.2

db.FirstTry.update({"id":1},{$set:{"Name":"Selvah"}}); I am getting an error like this { "message" : "WriteError({'code':10003,'index':0,'errmsg':'Cannot change the size of a document in a capped collection: 72 != …
Selvah
  • 25
  • 5
0
votes
0 answers

Mongo DB update did not update all records as expected

I am trying update a bulk of data in Mongo DB. Here is what I am trying to do: var bkdet = db.library.find(); bkdet.forEach(function(item){ //process item var rentDateWithoutTimestamp = item.book.rentDate; …
crazyProgrammer
  • 65
  • 1
  • 2
  • 7
0
votes
1 answer

mongodb: update query on an variable makes changes to another variable that's an array

Ran this via terminal on an existing mongodb database hosted in aws ec2 instance: db.users.update({},{ $inc: { point_total: 100 } }, {multi:true}) In additional to increasing variable by 100 for all users there were also entry changes to another…
Alexandra G
  • 61
  • 1
  • 3
0
votes
1 answer

Specify date format when updating date field in mongoDB document

I am using mongoDB 3.4 and want to close documents in a mongoDB collection by setting an EffectiveEndDateTime field to todays/current date time and want it in this format: yyyy-MM-dd HH:mm:ss.SSS. How can I specify the date format? My current…
user3165854
  • 1,505
  • 8
  • 48
  • 100
0
votes
5 answers

MongoDB update multiple subdocuments with or query

I want to make an update query for multiple subdocuments at once. I will be setting all the subdocuments statuses to passive where they satisfy the condition I give on query. db.deduplications.update( { $and: [ { "_id":…
Tolga Evcimen
  • 7,112
  • 11
  • 58
  • 91
0
votes
1 answer

Update multilevel embedded document

I have quite a complex data structure in mongoDB. The document looks like a little like this { "id" : 0, "basket" : [ { "price" : 0.9918, "id" : 2500, "exGroup" : [ { …
Richard B
  • 895
  • 13
  • 39
0
votes
1 answer

push elements into array

I have a collection named test looks like the following json: { '_id':ObjetcId("..."), 'a':[ { id:1, a1:[{x:1,y:1},{x:10,y:11},{x:10,y:12}], flag:1 }, { id:2 …
HaiFengZeng
  • 103
  • 10
0
votes
1 answer

How to update object in mongoose

I have a schema that looks like this: var userSchema = mongoose.Schema({ facebook : { id : String, token : String, email : String, name : String }, twitter …
Manos
  • 1,471
  • 1
  • 28
  • 45
0
votes
1 answer

MongoDB update query to unset specific array members based on the value

I have an array of sub-document like below /* record 1 */ { "_id" : "462044", "program" : [ { "name" : "Business…
1 2 3
12
13