Category "mongodb-query"

Match elements before and after some criteria

Suppose I have an ordered (by $sort aggregation pipeline stage) list of documents: { x: 0 } { x: 1 } { x: 3 } { x: 4 } { x: 5 } { x: 6 }

How to search for item in a list from MongoDB in react js?

I want to make a website where all my data come from MongoDB by fetch. In the search button, I want to get a single item by clicking the search button.

Mongo updateMany statement with date.withZoneSameInstant(xxx)

I have this collection in my Mongo database: id | place | local time -------------------------- 3 | A | 12pm 4 | A | 11pm 5 | B | 4pm

MongoDB aggregate for daily won/lost games, $cond is always false

I'm doing a couple of $match's and $unwind's and end up with a collection of documents looking like this: { _id:249776348, StartGameTime:1615789789, team:0, win

Script that returns _id in MongoDB with JavaScript

I need a javascript code that saves in a variable the _id I'm having trouble getting that _id because it’s inside an array. I have looked everywhere but I

$concat for one field in mongosh updateOne method

I want to update a particular document for the email field based on its id, but I don't want to overwrite the email field completely. Instead, I just want to ad

How to upsert object in Mongoose Array?

I want to edit an array with mongoose, if the object id already exist in the array, then it will create a new one, and if it exist, it will update. My code: con

Mongodb: Merge nested objects based on common identifier

I have 3 objects like this {"_id":{"$oid":"625f0e73b1d7269de9ebdaeb"}, "Type":"scalar", "Temperature":22.79, "Vibration":{"A-P2P":{"X":85},"Z2P":{"X":43},"Crest

How to projection fields for a dictionary (C#, MongdoDB)

I am trying my luck here, I have a model which is like the following public class RowData : BaseBsonDefinition { . [BsonExtraElements] [BsonDictionaryOption

Ways to update many nested Documents with MongoTemplate without creating additional Update object

I use MongoTemplate to update a document using findAndModify() method. There are nested documents inside one document. Example as following: @Document public cl

Overwrite value and create key while update query in mongodb

I have a mongodb collection that looks like this: { "_id" : ObjectId("60471bd482c0da3c0e70d26f"), "owner" : "John", "propAvailable" : { "

How to project only the fields present in an array in MongoDB?

there is a document schema that has an array field called "updatedFields" which contains some fields names that you will find in "oldDocument" and "newDocument"

$geoWithin return document located outside the polygon queried

I've recently came across this behaviour that I cannot explain. $geowithin return documents outside the polygon queried. To illustrate my problem, I've made a m

How to update key values by append the existing one for the record in MongoDb collection

I have a Collection allRecords as {'name':'tom', 'subjects':'Physics'} {'name':'jerry', 'subjects':'Maths'} I have one json file is testData.json as {names:",t

How to filter data in collection containing documents with 3 level nested arrays depending on the values in the first and last nested array mongo

I appreciate any help in such case. Collection in MongoDB (now only 4 documents for demonstration purpose): { "_id" : ObjectId("62684847e9594c65cbaa5d85

MongoDB how to update an object property in nested array

I have the following structure in my MongoDb where I have a topic object inside of a topics array. Within the topic object, I have a messages array. What I am t

mongodb command very slow

I have 3 documents like this: { _id: ObjectId("..."), _details: { _session: ObjectId("example_1"), }, { _id: ObjectId("..."), _details: { _session: Obje

Update a value in a nested field?

user :["id": 1, userObj:[{"bookid": 1, "library":"Oxford", "taken":true}, {"bookid": 2, "library":"Cambridge", "taken":true}]] I would like to update the value

Insert data with new fields OR update conditionally using updateOne mongodb

I have a document with format like this: { "f1": "v1", "f2": { "id": 1, "sub": "subv", "updatedAt": 123 } } I have an another source that

How to update ISODate to two days later

How to convert a SQL query to mongodb query? Please write a mongodb query - this is my query in SQL: UPDATE user SET expireIn = DATEADD(DAY, 2, expireIn) WHE