0% found this document useful (0 votes)
8 views

Notes 3

Uploaded by

tripathirajju431
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views

Notes 3

Uploaded by

tripathirajju431
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 44

Editing "MongoDB" 28/05/23, 7:22 PM

Add Cover Add Subtitle

MongoDB

Using MongoDB
Open MongoDB in the terminal:
Write mongosh in your terminal, and it will open the
MongoDB console.

You can also use MongoDB Compass software, to


open the same terminal directly.

https://hashnode.com/draft/6471f3c0de2159000f618c28 Page 1 of 44
Editing "MongoDB" 28/05/23, 7:22 PM

List all databases in mongodb


To list all the databases stored in your mongodb
we can use the below commands:

JavaScript

show databases;

We can also use the below command:

JavaScript

show dbs;

https://hashnode.com/draft/6471f3c0de2159000f618c28 Page 2 of 44
Editing "MongoDB" 28/05/23, 7:22 PM

How to select a particular


DB to work on?
To select a particular db and start querying on it
we can use

https://hashnode.com/draft/6471f3c0de2159000f618c28 Page 3 of 44
Editing "MongoDB" 28/05/23, 7:22 PM

JavaScript

use name_of_database;

How to print all the collections


stored in a database ?
To print all the collections we can use:

JavaScript

show collections;

Make sure, we run this command after executing


use some_db otherwise we wont be having db
selected.

https://hashnode.com/draft/6471f3c0de2159000f618c28 Page 4 of 44
Editing "MongoDB" 28/05/23, 7:22 PM

How to print all the documents of


a collection ?
To print all the documents of a collection we can
use:

JavaScript

db.collectionname.find();

https://hashnode.com/draft/6471f3c0de2159000f618c28 Page 5 of 44
Editing "MongoDB" 28/05/23, 7:22 PM

How to create a new database ?


To create a new database we can do:

JavaScript

use new_database_name;

The use command creates a new database if


there is no already present db with the same
name, otherwise if there is a db with the same
name, it just selects it.

https://hashnode.com/draft/6471f3c0de2159000f618c28 Page 6 of 44
Editing "MongoDB" 28/05/23, 7:22 PM

Now what will happen is, after creating a DB, if we


try to do show dbs; then it will not list our newly
created database. Because, if mondodb sees that
there is no valid collection added in the database,
and the db is empty, it doesn’t list it.

https://hashnode.com/draft/6471f3c0de2159000f618c28 Page 7 of 44
Editing "MongoDB" 28/05/23, 7:22 PM

So how to add a new collection?

How to add new collections?


To create a new collection we can do:

JavaScript

db.createCollection("name_of_the_collec
tion")

https://hashnode.com/draft/6471f3c0de2159000f618c28 Page 8 of 44
Editing "MongoDB" 28/05/23, 7:22 PM

Make sure we execute this command after use


some_db_name

In normal RDBMS, while creating a table, we have


to define what will be the column of the table. Why
we are not defining the properties of a collection
on Mongodb?

This is because, MongoDB doesn’t restrict us by


any means for defining documents of a collection.
Two documents of the same collection can
possess different types of properties.

https://hashnode.com/draft/6471f3c0de2159000f618c28 Page 9 of 44
Editing "MongoDB" 28/05/23, 7:22 PM

How to add a new record to a


collection?
To add a new record we can do:

JavaScript

db.collectionName.insertOne({key1:
value1, key2: value2 ....})

How to add multiple records


together?
To add multiple records at once in MongoDB we
can use:

https://hashnode.com/draft/6471f3c0de2159000f618c28 Page 10 of 44
Editing "MongoDB" 28/05/23, 7:22 PM

JavaScript

db.collectionName.insertMany([
{
key1: value1,
key2: value2
},
{
key1: value1,
key2: value2,
key3: value3,
.
.
.
},
{
key5: value5,
key7: value7,
.
.
}
]);

https://hashnode.com/draft/6471f3c0de2159000f618c28 Page 11 of 44
Editing "MongoDB" 28/05/23, 7:22 PM

Can we add an array in the JSON


in MongoDB?
We can simply use [] to add an array.

How to import sample


DB in MongoDB?
To get some free sample datasets you can check
out this Github link:
https://github.com/neelabalan/mongodb-sample-
dataset.

You can pick any folder and download the dataset


which is present in JSON format.

https://hashnode.com/draft/6471f3c0de2159000f618c28 Page 12 of 44
Editing "MongoDB" 28/05/23, 7:22 PM

After the file is downloaded you can import this


data using MongoDB Compass.

Create a new Database (we can directly


create it using MongoDB Compass)

We can give a name to the database and give

https://hashnode.com/draft/6471f3c0de2159000f618c28 Page 13 of 44
Editing "MongoDB" 28/05/23, 7:22 PM

the first collection name also directly using


MongoDB Compass.

Once you click on create a database, a brand


new empty db will be created.

Now click on Add Data, which will give you

https://hashnode.com/draft/6471f3c0de2159000f618c28 Page 14 of 44
Editing "MongoDB" 28/05/23, 7:22 PM

two options:

Either you can import from JSON or CSV

Or you can manually insert the document.

We will go for Option 1.

It will open the file explorer where you can


select the JSON we just downloaded.

https://hashnode.com/draft/6471f3c0de2159000f618c28 Page 15 of 44
Editing "MongoDB" 28/05/23, 7:22 PM

Click on import and it will automatically import


the data from the JSON

After it finishes importing, it should look like


this:

https://hashnode.com/draft/6471f3c0de2159000f618c28 Page 16 of 44
Editing "MongoDB" 28/05/23, 7:22 PM

How to import without


MongoDB Compass?
We can use a terminal or CMD to import
data without a compass.

Open your terminal or CMD.

Change the directory to the one where


you have downloaded the JSON. If you are
using Windows refer to this link to
understand how to change the directory
from cmd.

https://hashnode.com/draft/6471f3c0de2159000f618c28 Page 17 of 44
Editing "MongoDB" 28/05/23, 7:22 PM

Now we can use a MongoDB tool called as


mongoimport (generally by default installed
with MongoDB). We can use the following
command:

JavaScript

mongoimport --db db_name --


collection collection_name --file
data.json;

You can check the import directly from


mongosh or compass

https://hashnode.com/draft/6471f3c0de2159000f618c28 Page 18 of 44
Editing "MongoDB" 28/05/23, 7:22 PM

Let's explore the DB we


imported

How to see the count of


documents in a collection?

https://hashnode.com/draft/6471f3c0de2159000f618c28 Page 19 of 44
Editing "MongoDB" 28/05/23, 7:22 PM

There is a count function that we can use

JavaScript

db.collectionName.find().count();

How to handle the printing of


huge amounts of data?
If you have a huge amount of data, just like we
have here approx 10,000 documents, if you try to
execute db.collectionName.find in your mongosh
then will not print all the 10,000 records, because
it cannot handle that in the shell. If you try it then
in the console, it will print some data and then
gives you a prompt of Try "it" for more

https://hashnode.com/draft/6471f3c0de2159000f618c28 Page 20 of 44
Editing "MongoDB" 28/05/23, 7:22 PM

If you write it and press enter then you will get


next group of data.

How to get a certain number of


documents?
https://hashnode.com/draft/6471f3c0de2159000f618c28 Page 21 of 44
Editing "MongoDB" 28/05/23, 7:22 PM

We can use a function called as limit

JavaScript

db.collectionName.find().limit(no_of_re
cords_to_fetch);

mongoshmongodb:|/127.0.0.1:27017/?directConnection=true&serverSelectionTimeoutMS=2000(I?directConnection=true\&se)961 ~/Downloads

new_weather_db>db.weather_data.find().limit(3)
{

_id:ObjectId("5553a998e4b02cf7151190b9"),
st:'x+45200-066500',
ts:ISODate("1984-03-05T14:00:00.000Z"),
position:{type:'Point',coordinates:1-66.5,45.21},
elevation:9999,
callLetters:'VC81',
qualityControlProcess:'V020',
dataSource:'4'
type:'FM-13'
airTemperature:{value:-4.7,quality:'1'},
dewPoint:{value:999.9,quality:'9'3,
pressure:€value:1025.9,quality:'1'},
wind:{

direction:Iangle:999,quality:'9'3,
type:'9',
speed:<rate:999.9,quality:'9'}
},
visibility:{
distance:{value:999999,quality:'9'3,
How to set an offset while
variability:{value:'N',quality:'9'}
3,

querying data?
skyCondition:{
ceilingHeight:{value:99999,quality:'9',determination:'9'3,
cavok:'N'
},
Wesections:['AGI'1,
can set an offset using the skip function.
precipitationEstimatedObservation:discrepancy:'2',estimatedWaterDepth:999}
3,
Using the skip function we can skip some records
and then start fetching records post the skip.

JavaScript

https://hashnode.com/draft/6471f3c0de2159000f618c28 Page 22 of 44
Editing "MongoDB" 28/05/23, 7:22 PM

db.collectionName.find().skip(5).limit(
3)

How do filter records based on a


condition?
To filter the records, we can pass an object in the
arguments of the find function, where we can add
out conditions.

JavaScript

db.collectionName.find({key1: value1,
key2: value2})

https://hashnode.com/draft/6471f3c0de2159000f618c28 Page 23 of 44
Editing "MongoDB" 28/05/23, 7:22 PM

Projections
If we want to not get all the properties of the
JSON, and instead get some specific key-value
pairs, this process is called Projection. In the world
of SQL, if you do SELECT * FROM TABLE; then you
get all the columns but if you do SELECT name,
address FROM TABLE; you only get name and
address. This same thing is achieved in Projections.

How to do projections?

So the first argument of the find function is an


object which takes filtration criteria. It can accept
another argument as an object, where we can
write whatever properties we have to include and
assign them a value true.

JavaScript

db.collectionName.find({filter1:
value1...}, {property1: true,
property2: true....});

https://hashnode.com/draft/6471f3c0de2159000f618c28 Page 24 of 44
Editing "MongoDB" 28/05/23, 7:22 PM

You can also pass the first argument as an empty


JSON object.

If we want to manually exclude specific properties,


you can write their names with false value
allocated:

Now this will bring everything apart from


pastWeatherObservationManual and
skyConditionObservation

How to delete a document?


If we want to delete some documents we can use
functions like deleteOne , deleteMany and
findByIdAndDelete .

JavaScript

db.collectionName.deleteOne({filter1:

https://hashnode.com/draft/6471f3c0de2159000f618c28 Page 25 of 44
Editing "MongoDB" 28/05/23, 7:22 PM

value1, filter2: value2..});

JavaScript

db.collectionName.deleteMany({filter1:
value1, filter2: value2..});

new_weather_b>db.weather_data.deleteOne({_id:ObjectId("5553a998
{acknowledged:true,deletedCount:1}
new_weather_db>db.weather_data.find(f_id:ObjectId("5553a998e4b02
newweatherdb>

We can similarly use findOneAndDelete to filter the


data and then delete one record it. Docs

How to update a record?

https://hashnode.com/draft/6471f3c0de2159000f618c28 Page 26 of 44
Editing "MongoDB" 28/05/23, 7:22 PM

To Update records we can use updateOne ,


updateMany and a few similar functions. These
functions take two arguments,

!" Filtration criteria viz. how to filter what data to


update

$" With what value we should update

JavaScript

db.collectionName.updateOne({filter1:
value1}, {$operator: {key1: value1,
key2: value2...}})

Now MongoDB provides us with some operators


for these updates for example:

$set -> This will allocate the value to the key


directly passed in the object

$inc -> This will increment the value in the key

https://hashnode.com/draft/6471f3c0de2159000f618c28 Page 27 of 44
Editing "MongoDB" 28/05/23, 7:22 PM

To decrease we can do $inc with a negative value.

new-_weather_b>db.weather_data.updateOne(<_id:ObjectId("5553a998e4b02cf7151190c0")},
{
acknowledged:true,
insertedId:null,
matchedCount:1,
modifiedCount:1,
upsertedCount:0

If you will use updateMany then all the records


which are complying with the filtration criteria will
be updated.

How to get distinct values of a


particular key?
We can use the distinct function in order to get
all distinct values of a particular key.

JavaScript

db.collectionName.distinct("key");

https://hashnode.com/draft/6471f3c0de2159000f618c28 Page 28 of 44
Editing "MongoDB" 28/05/23, 7:22 PM

Weather>db.weather_data.distinct("type")
['FM-13', 'SAO'1
Weather>db.weather_data.distinct("callLetters")
'OBVZ' 'OJSV', '2100'"3DRO'. '3DRV' "ЗЕВА'
"ЗЕЕК" "BEFT' "BEFO' "BEGC"
'BEGU'
"ЗЕНН' '3EIZ 'BEJF' 'BELE'.
'BEOS' 'BEOU' "ЗЕРА' 'BEON' "BERJ' '3ERZ'
"3EWO", "3EXD 'BEYN' '3EZL', '3FAR' "3FBD'
"3FEV' '3FGE', '3FJR', "ЗЕКА' "3FMV'
'3FTJ' '3FXH', "3FXS' "3FYO
'ДРКУ" "AXIC' 'AXII' 'AXIL' 'AXLU 'AXLZ'
'5LEX' 15LJT' '5LLP' 15LOT' 15L0Z '5LTW'
'5LWE'.'5LWG' '5LWO' "5MCB'. "5MCN '5MGC',
'5MTS' '5MZH' '5PVN', '67AM' '6ZAS' '67BM'
Operators
'6ZDN' '6ZFM' in MongoDB
'6ZHX', '6ZJP' '6ZLH' '6ZRT'
'7FFC' "7JEY' "7JKS' "ZIKY' "7JOB'
MongoDB '7J0x',
"7JOI'provides 'ZIRZ',
different '7J50',
comparison, "7JSP 171т11
logical,
'ZJUI',
bitwise JVMthat
etc operators
'7
', we can use very easily.
...2549moreitems
To use these operators for comparison and logical
operations, instead of directly assigning a key-
value pair for your filters etc, put your key and
assign it an object, inside the assigned object, put
the key as your operator and value as the value to
put.

https://hashnode.com/draft/6471f3c0de2159000f618c28 Page 29 of 44
Editing "MongoDB" 28/05/23, 7:22 PM

JavaScript

db.collectionName.find({property:
{$operator: value}})

Weather>db.weather_data.find({type:{$ne:'FM-1
6
Weather>

Commonly used operators:


$ne -> not equals

$eq -> equals

$lt -> less than

$lte -> less than or equal to

$gt -> greater than

$gte -> greater than or equal to

$and -> logical and

$or -> logical or

$not -> logical not

$nor -> logical nor

$in -> for checking in the array

https://hashnode.com/draft/6471f3c0de2159000f618c28 Page 30 of 44
Editing "MongoDB" 28/05/23, 7:22 PM

$nin -> not in the array

If you want to find all the records based on a


property and compare that with a bunch of values
in an array such that the property should be equal
to any one of them then we can use $in

Weather>db.weather_data.find({callLetters:f$in:['ЗЕН','EIZ',
17
Weather>

Analysing queries
We can analyse our queries using the explain
function. Inside this function, we can pass an
argument executionStats and it will provide us
with the details

https://hashnode.com/draft/6471f3c0de2159000f618c28 Page 31 of 44
Editing "MongoDB" 28/05/23, 7:22 PM

Bash

db.weather_data.find({type:
'SAO'}).explain("executionStats")

JSON

{
explainVersion: '1',
queryPlanner: {
namespace: 'Weather.weather_data',
indexFilterSet: false,
parsedQuery: { type: { '$eq': 'SAO'
} },
maxIndexedOrSolutionsReached:
false,
maxIndexedAndSolutionsReached:
false,
maxScansToExplodeReached: false,
winningPlan: {
stage: 'COLLSCAN',
filter: { type: { '$eq': 'SAO' }
},
direction: 'forward'
},
rejectedPlans: []
},

https://hashnode.com/draft/6471f3c0de2159000f618c28 Page 32 of 44
Editing "MongoDB" 28/05/23, 7:22 PM

executionStats: {
executionSuccess: true,
nReturned: 6,
executionTimeMillis: 31,
totalKeysExamined: 0,
totalDocsExamined: 10000,
executionStages: {
stage: 'COLLSCAN',
filter: { type: { '$eq': 'SAO' }
},
nReturned: 6,
executionTimeMillisEstimate: 0,
works: 10002,
advanced: 6,
needTime: 9995,
needYield: 0,
saveState: 10,
restoreState: 10,
isEOF: 1,
direction: 'forward',
docsExamined: 10000
}
},
command: { find: 'weather_data',
filter: { type: 'SAO' }, '$db':
'Weather' },
serverInfo: {
host: 'Sankets-MacBook-Pro.local',

https://hashnode.com/draft/6471f3c0de2159000f618c28 Page 33 of 44
Editing "MongoDB" 28/05/23, 7:22 PM

port: 27017,
version: '5.0.7',
gitVersion:
'b977129dc70eed766cbee7e412d901ee213acb
da'
},
serverParameters: {
internalQueryFacetBufferSizeBytes:
104857600,

internalQueryFacetMaxOutputDocSizeBytes
: 104857600,

internalLookupStageIntermediateDocument
MaxSizeBytes: 104857600,

internalDocumentSourceGroupMaxMemoryByt
es: 104857600,

internalQueryMaxBlockingSortMemoryUsage
Bytes: 104857600,

internalQueryProhibitBlockingMergeOnMon
goS: 0,
internalQueryMaxAddToSetBytes:
104857600,

internalDocumentSourceSetWindowFieldsMa

https://hashnode.com/draft/6471f3c0de2159000f618c28 Page 34 of 44
Editing "MongoDB" 28/05/23, 7:22 PM

xMemoryBytes: 104857600
},
ok: 1
}

Indexing
Indexing is a mechanism using which a database
prepared more data structures to store data in a
particular order based on particular keys, for faster
search.

Saved Upgrade Preview Publish

List all indexes present in the


collection

Weather>db.weather_data.getIndexes()

{v:2,key:{_id:13,name:'_id_'}
{v:2,key:{elevation:1},name:'elevation1'
V:2,
key:{elevation:1,'airTemperature.value':1},
name:'elevation_1_airTemperature.value_1'
},
To{v:2,key:{'dewPoint.value':1},name:'dewPoi
remove an index from the
collection
https://hashnode.com/draft/6471f3c0de2159000f618c28 Page 35 of 44
Editing "MongoDB" 28/05/23, 7:22 PM

Weather>ob.weather_data.dropIndex\'elevation_1')
{nIndexesWas:4,ok:1}
Weather>db.weather_data.getIndexes()

{v:2,key:{._id:17,name:_id_'3,

V:2,
key:{elevation:1,'airTemperature.value':1},
name:'elevation_1_airTemperature.value_1
},
To{v:2,key:{'dewPoint.value':1},name:'dewPoint
create an index for a collection

new_weather_db>db.weather_data.createIndex(
elevation1

Analysing indexes
Before we created our index on the elevation
property we were reading all the docs i.e. approx
9991 docs, to fetch all the docs with elevation less
than 5000.

JSON

{
explainVersion: '1',
queryPlanner: {
namespace:
'new_weather_db.weather_data',
indexFilterSet: false,

https://hashnode.com/draft/6471f3c0de2159000f618c28 Page 36 of 44
Editing "MongoDB" 28/05/23, 7:22 PM

parsedQuery: { elevation: { '$lt':


8000 } },
maxIndexedOrSolutionsReached:
false,
maxIndexedAndSolutionsReached:
false,
maxScansToExplodeReached: false,
winningPlan: {
stage: 'COLLSCAN',
filter: { elevation: { '$lt':
8000 } },
direction: 'forward'
},
rejectedPlans: []
},
executionStats: {
executionSuccess: true,
nReturned: 6,
executionTimeMillis: 27,
totalKeysExamined: 0,
totalDocsExamined: 9991,
executionStages: {
stage: 'COLLSCAN',
filter: { elevation: { '$lt':
8000 } },
nReturned: 6,
executionTimeMillisEstimate: 5,
works: 9993,

https://hashnode.com/draft/6471f3c0de2159000f618c28 Page 37 of 44
Editing "MongoDB" 28/05/23, 7:22 PM

advanced: 6,
needTime: 9986,
needYield: 0,
saveState: 9,
restoreState: 9,
isEOF: 1,
direction: 'forward',
docsExamined: 9991
}
},
command: {
find: 'weather_data',
filter: { elevation: { '$lt': 8000
} },
'$db': 'new_weather_db'
},
serverInfo: {
host: 'Sankets-MacBook-Pro.local',
port: 27017,
version: '5.0.7',
gitVersion:
'b977129dc70eed766cbee7e412d901ee213acb
da'
},
serverParameters: {
internalQueryFacetBufferSizeBytes:
104857600,

https://hashnode.com/draft/6471f3c0de2159000f618c28 Page 38 of 44
Editing "MongoDB" 28/05/23, 7:22 PM

internalQueryFacetMaxOutputDocSizeBytes
: 104857600,

internalLookupStageIntermediateDocument
MaxSizeBytes: 104857600,

internalDocumentSourceGroupMaxMemoryByt
es: 104857600,

internalQueryMaxBlockingSortMemoryUsage
Bytes: 104857600,

internalQueryProhibitBlockingMergeOnMon
goS: 0,
internalQueryMaxAddToSetBytes:
104857600,

internalDocumentSourceSetWindowFieldsMa
xMemoryBytes: 104857600
},
ok: 1
}

But after creating an index this number will


decrease drastically.

JSON
https://hashnode.com/draft/6471f3c0de2159000f618c28 Page 39 of 44
Editing "MongoDB" 28/05/23, 7:22 PM

JSON
{
explainVersion: '1',
queryPlanner: {
namespace:
'new_weather_db.weather_data',
indexFilterSet: false,
parsedQuery: { elevation: { '$lt':
8000 } },
maxIndexedOrSolutionsReached:
false,
maxIndexedAndSolutionsReached:
false,
maxScansToExplodeReached: false,
winningPlan: {
stage: 'FETCH',
inputStage: {
stage: 'IXSCAN',
keyPattern: { elevation: 1 },
indexName: 'elevation_1',
isMultiKey: false,
multiKeyPaths: { elevation: []
},
isUnique: false,
isSparse: false,
isPartial: false,
indexVersion: 2,
direction: 'forward',
indexBounds: { elevation: [ '[-

https://hashnode.com/draft/6471f3c0de2159000f618c28 Page 40 of 44
Editing "MongoDB" 28/05/23, 7:22 PM

inf.0, 8000)' ] }
}
},
rejectedPlans: []
},
executionStats: {
executionSuccess: true,
nReturned: 6,
executionTimeMillis: 2,
totalKeysExamined: 6,
totalDocsExamined: 6,
executionStages: {
stage: 'FETCH',
nReturned: 6,
executionTimeMillisEstimate: 0,
works: 7,
advanced: 6,
needTime: 0,
needYield: 0,
saveState: 0,
restoreState: 0,
isEOF: 1,
docsExamined: 6,
alreadyHasObj: 0,
inputStage: {
stage: 'IXSCAN',
nReturned: 6,
executionTimeMillisEstimate: 0,

https://hashnode.com/draft/6471f3c0de2159000f618c28 Page 41 of 44
Editing "MongoDB" 28/05/23, 7:22 PM

works: 7,
advanced: 6,
needTime: 0,
needYield: 0,
saveState: 0,
restoreState: 0,
isEOF: 1,
keyPattern: { elevation: 1 },
indexName: 'elevation_1',
isMultiKey: false,
multiKeyPaths: { elevation: []
},
isUnique: false,
isSparse: false,
isPartial: false,
indexVersion: 2,
direction: 'forward',
indexBounds: { elevation: [ '[-
inf.0, 8000)' ] },
keysExamined: 6,
seeks: 1,
dupsTested: 0,
dupsDropped: 0
}
}
},
command: {
find: 'weather_data',

https://hashnode.com/draft/6471f3c0de2159000f618c28 Page 42 of 44
Editing "MongoDB" 28/05/23, 7:22 PM

filter: { elevation: { '$lt': 8000


} },
'$db': 'new_weather_db'
},
serverInfo: {
host: 'Sankets-MacBook-Pro.local',
port: 27017,
version: '5.0.7',
gitVersion:
'b977129dc70eed766cbee7e412d901ee213acb
da'
},
serverParameters: {
internalQueryFacetBufferSizeBytes:
104857600,

internalQueryFacetMaxOutputDocSizeBytes
: 104857600,

internalLookupStageIntermediateDocument
MaxSizeBytes: 104857600,

internalDocumentSourceGroupMaxMemoryByt
es: 104857600,

internalQueryMaxBlockingSortMemoryUsage
Bytes: 104857600,

https://hashnode.com/draft/6471f3c0de2159000f618c28 Page 43 of 44
Editing "MongoDB" 28/05/23, 7:22 PM

internalQueryProhibitBlockingMergeOnMon
goS: 0,
internalQueryMaxAddToSetBytes:
104857600,

internalDocumentSourceSetWindowFieldsMa
xMemoryBytes: 104857600
},
ok: 1
}

If you will check the docsExamined property of the


above 2 JSONs, you can see a significant
difference.

https://hashnode.com/draft/6471f3c0de2159000f618c28 Page 44 of 44

You might also like