All Questions
Tagged with insert-update mongodb
91
questions
0
votes
1
answer
51
views
Batch update of records in MongoDB
I iterated over records in the batch step and in Batch Aggregator I wanted to update all of them at once in mongoDb. Is there a way to update them all together or I need to separately update each one ...
1
vote
1
answer
25
views
Update many documents by pushing an object to an array field when id field matches the id field in the object
Ok that question doesn't sound very clear. I will try to explain.
I have a collection of F1 drivers that contains an array field to store the points earned from each race.
I use a web form to submit ...
0
votes
1
answer
76
views
mongodb update one with upset is not working as expected
This is my mongoose schema.
const CurrencySchema = new mongoose.Schema({
source: { type: String, uppercase: true, required: true, minlength: 3, maxlength: 3, trim: true },
convert: { type: ...
0
votes
1
answer
23
views
Mongoose express server throws, Cast to string failed for value, error when I try to update a db entry
I have this mongoose express function:
exports.updateSingleAddress = (req, res) => {
let keyPassed = req.body.key;
let addressPassed = req.body.address;
if (!keyPassed) {
keyPassed = '...
0
votes
1
answer
362
views
How to change name of a field in MongoDB with java for each document in the collection?
Due to some decisions I will have to change the name of some fields in all documents in a single collection. For purpose of automation testing I am inserting documents and then checking some logics.
...
3
votes
2
answers
2k
views
Difference between the UpdateOne() and findOneAndUpdate Methods in Mongo DB
What is the difference between the UpdateOne() and the findOneAndUpdate() methods in Mongo DB?
I can't seem o understand their differences. Would appreciate it if a demonstrative example using ...
1
vote
1
answer
434
views
Swap elements in a MongoDB array given only their ids (in-place)
I read some threads about it, such as this one and that one, but they both come with major flaws & caveats (to me at least).
What I want is simple! An update query that:
swaps 2 elements in an ...
2
votes
0
answers
392
views
Golang-Mongodb Insert element of array inside another array maintaining uniqueness of array
Currently I am learning learn to create restful api with golang and mongodb. I am using mongo-go-driver. I got stuck at this.
Let's say I have a collection that has document entries with the structure ...
0
votes
1
answer
53
views
how to modify every field of a nested document mongo?
so imagine I have the following document:
{
"_id":...,
"data":{"a":[],"b":[],"x":[]}
}
I don't know beforehand which fields the subdocument data ...
0
votes
1
answer
258
views
Push data in mongodb use value from another field
I use mongoose for push data(use a value from rank_num field) to a field like this:
ListM.findOneAndUpdate({userId: req.body.userId},
[{
$push: {
listData: {
...
1
vote
1
answer
72
views
MongoDB "update()" (Update the document of “Reg Rubio” and “Ian Tayao” by adding the “President” to their Reporting file)
I use this codes manually
db.employees.update({Name: "Reg Rubio"}, {$set : {ReportingTo: ["Vice-President", "President"]}})
db.employees.update({Name: "Ian Tayao&...
0
votes
1
answer
50
views
MongoDB, update an existing collection via aggregate
I have following mongodb collection
{
"_id" : "B0006ZPB0S",
"title" : "Pretty Diamond-cut Black Hills Gold & Sterling Silver Rose Bud Women's Ring&...
2
votes
0
answers
231
views
Update (increment) array's object field or create (if not exists) whole document - MongoDb
I'd like to increment some field in nested array or if document not exists, or object in array - create them.
Example of existing filled document:
{
_id: "some_id_1",
my_objects: [
{
...
1
vote
1
answer
357
views
Replace old records while inserting new duplicate records in Mongoose
The mongoDB collection:
db.collection.find()
{ _id:'...', emp: 'A', name: 'nameA', age: 23 }
{ _id:'...', emp: 'B', name: 'nameB', age: 54 }
{ _id:'...', emp: 'C', name: 'nameC', age: 45 }
The ...
1
vote
0
answers
167
views
Update and insert multiple documents in mongodb
I was trying to update and insert many input documents into mongodb.
I found many resources, but didn't get the optimal solution except bulkWrite.
My documents looks like below.
[
{
pId: &...