'mongodb': how to retrieve values from an object in shell script

I use a shell script to query MongoDB: #!/bin/bash mongoexport -d db -c collection -f Id I have: { _id: ObjectId("641e883ec0a3fde195b59019"), Id: ‘12027311490’ }, { _id: ObjectId("641e8845c0a3fde195b5901b"), Id: ‘15400490185’ }, { _id: ObjectId("641e884dc0a3fde195b5901d"), Id: ‘775662862079’ }, { _id: ObjectId("641e8852c0a3fde195b5901f"), Id: ‘68236165355’ }, { _id: ObjectId("641e885ac0a3fde195b59021"), Id: ‘74174554856’ }, { _id: ObjectId("641e8861c0a3fde195b59023"), Id: ‘525514528629’ }, {… Read More 'mongodb': how to retrieve values from an object in shell script

How to update mongodb array of ObjectId to array of objects?

I want to update an array field in a document to array of object. from: { _id: ObjectId("634a84bc0c43db0c08596fda"), array1: [ObjectId("61542ed38929eff201f1a449"), ObjectId("61542ed38929eff201f1a450")] } to: { _id: ObjectId("634a84bc0c43db0c08596fda"), array1: [ { _id: ObjectId("634a84bc0c43db0c08596fd0") doc2: ObjectId("61542ed38929eff201f1a449") }, { _id: ObjectId("634a84bc0c43db0c08596fd1") doc2: ObjectId("61542ed38929eff201f1a450") } ] } This is what I tried: db.doc1.aggregate( [ { $match: { _id: ObjectId(‘634a84bc0c43db0c08596fda’) }… Read More How to update mongodb array of ObjectId to array of objects?

How to update mongodb array of ObjectId to array of objects?

I want to update an array field in a document to array of object. from: { _id: ObjectId("634a84bc0c43db0c08596fda"), array1: [ObjectId("61542ed38929eff201f1a449"), ObjectId("61542ed38929eff201f1a450")] } to: { _id: ObjectId("634a84bc0c43db0c08596fda"), array1: [ { _id: ObjectId("634a84bc0c43db0c08596fd0") doc2: ObjectId("61542ed38929eff201f1a449") }, { _id: ObjectId("634a84bc0c43db0c08596fd1") doc2: ObjectId("61542ed38929eff201f1a450") } ] } This is what I tried: db.doc1.aggregate( [ { $match: { _id: ObjectId(‘634a84bc0c43db0c08596fda’) }… Read More How to update mongodb array of ObjectId to array of objects?

How to update nested documents in an array in mongodb document without using positional operator $?

I have an issue in which I am not able to use the positional operator to update subdocuments because I am using MongoDB version 3.2 which doesn’t support the positional operator $, and I am not able to upgrade MongoDB version to more than 3.2 due to the 32-bit MongoDB support I want to change… Read More How to update nested documents in an array in mongodb document without using positional operator $?

how can I modify a field name / key in a nested array of objects in mongodb?

I have a mongodb collection with a number of objects like this: { "_id" : "1234", "type" : "automatic", "subtypes" : [ { "_id" : "dfgd", "name" : "test subtype", "subjetRequired" : true, }, { "_id" : "dfgd", "name" : "test subtype2", "subjetRequired" : false, } ], "anotherField" : "some value" } As you can… Read More how can I modify a field name / key in a nested array of objects in mongodb?

How to create a GridFSBucket and add a file in this a bucket with mongosh?

I want to create a GridFS bucket with mongosh and create files in this bucket. I tried to follow this documentation : https://www.mongodb.com/docs/drivers/node/current/fundamentals/gridfs/ But i’m stuck with errors : > use myDb > bucket=new mongo.GridFSBucket(db, { bucketName: ‘myCustomBucket’ }); ReferenceError: mongo is not defined > var mongodb = require(‘mongodb’); > bucket=new mongodb.GridFSBucket(db, { bucketName: ‘myCustomBucket’… Read More How to create a GridFSBucket and add a file in this a bucket with mongosh?