Category "mongodb-query"

How to query Child Reference Pattern collection with $graphLookup

I have a collection with child reference. Each document can have multiple parents. How can I query it with $graphLookup in order to make a result prepared for a

Access root document map in the $filter aggregation (MongoDb)

I apologize for the vague question description, but I have quite a complex question regarding filtration in MongoDB aggregations. Please, see my data schema to

How to delete and insert with a single command in mongoDB?

So, I have a collection like this: [{ "name":String, "address":String, "hobby":Array of Strings }...] Every hour I query an API and get the response l

how to replaceOne document in MongoDb with Mongo database command

We have requirement to execute replaceOne operation with db.runCommand() I checked list of commands from here, but i haven't found any command to replace one do

How to filter documents by having a list of words which should not be inside of them in MongoDB Atlas Search?

For example I have the array ["java", "perl", "scrum"] and the following documents: { id: 1, title: "Java Software Developer" }, { id: 2, title: "Senior

How to skip a document from retrieving in MongoRepository if it causes an error?

I'm working on a web application built using SpringBoot as backend and MongoDB as DBMS. I'm showing all the latest posts in a web page. In the PostRepository.kt

MongoDB insertMany and skip duplicates

I'm trying to insertMany() items into my Mongo database but I would like to skip duplicate IDs. I'm using Node.js and mongodb. I have some data: const myExam

Mongodb query with multiple $or inside $and

I want records which if type have 0 or 2 than status should not equal to 0 and if type = 3 then ignore status. I tried this way but not working. db.activities.f

Zsh: Command Not found : mongo After trying to install mongodb 4.2 using brew

I have tried the following steps to install and setup mongodb in my mac from here https://docs.mongodb.com/manual/tutorial/install-mongodb-on-os-x/ but I got th

MongoDB - Update an Key

I have been trying to update an Object for this collection. Below is the collection. Looking for Server 3.6 version. Here The ask is Need to update the class na

Mongoose - Update an object inside nested array

My Mongo schema looks like this, I want to update a flashcard object located in an array of flashcard also located in an array of subject. const classrooms = ne

MongoDB query to find top store from list of orders

I'm pretty new to Mongo. I have two collections that look as follows. Order collection [ { id: 1, price: 249, store: 1, status: true

MongoDB - Loop through array of arrays

I have a document that contains an array of arrays in my MongoDB collection. { "platformId":"CMC_123", "carInfo":[ ["Toyota",20,"White"],

Document Read and insert with locking/transaction in nodejs with mongodb

In reservation system, only 5 different user can create bookings. If 100 user call booking api at same time than how to handle concurrency with locking. I am us

MongoDB Shell deleteMany() function is not working

I have to delete all the data called owner.login. It means in json data, there are one more Object called owner. So I tried in MongoSH Beta(MongoDB Compasss) an

Trying to call function by using db.eval("functionName()") in mongoDB compass version 4.4 But getting error as TypeError: db.eval is not a function

db.system.js.insertOne({ _id: 'getMachinewiseLogDat', value: function () { return db.Smx_22235_ShiftOEEDaily.aggregate([ { $group: {

How to create nested array inside $group in MongoDB?

After some of the aggregation pipeline stages, my MongoDB Document has the following format: { "key": "A", "status": "To Do", "val": 4 }, {

Remove specific object from array during aggregation

I have documents with the following structure: {field: ["id1", "id3"]}, {field: ["id2", "id1"]} To query the documents I use aggregate({$match: {'field' : { $i

MongoDB : How to update a new field value according to existing field value in each document?

I am working on a project and it currently goes through each document to edit the field and lags a lot. { "Name" : "Susie" , "This Semester" : 10 , "Last Semest

MongoDB query inside an array

I want to use this mongoDB collection: [ { "_id": { "$oid": "627c4eb87e7c2b8ba510ac4c" }, "Contact": [ { "name": "ABC",