Atikh's DBA blog
  • Home
  • Oracle
  • MySQL
  • MongoDB
  • PostgreSQL
  • Snowflake
  • About Me
  • Contact Us

MongoDB : Creating a Large Document

 Atikh Shaikh     MongoDB     No comments   

In order to try various queries or to check the performance of the database, we need to have large enough documents; here we will create a couple of large documents and try to query those with different operators and functions available in MongoDB

MongoDB Create Large Documents and query, create document, select document, query document, MongoDB, MongoDB DBA

In the below examples we will create two collections techno_col and tech_large with 2000 and 15000 documents in it. Insertion might take some time depending on number of documents

> for (i = 0; i < 2000; i++) { db.techno_col.save({num: i}); }
WriteResult({ "nInserted" : 1 })
> 
> db.techno_col.count();
2000
> 
> for(i = 0;  i < 15000;  i++) {db.tech_large.save({emp_id : i});};
WriteResult({ "nInserted" : 1 })
> 

> db.tech_large.count();
15000
> 

Now try to query documents from techno_col collections, 

> db.techno_col.find()
{ "_id" : ObjectId("5c5d66a310f3108c3c83d574"), "num" : 0 }
{ "_id" : ObjectId("5c5d66a310f3108c3c83d575"), "num" : 1 }
{ "_id" : ObjectId("5c5d66a310f3108c3c83d576"), "num" : 2 }
{ "_id" : ObjectId("5c5d66a310f3108c3c83d577"), "num" : 3 }
{ "_id" : ObjectId("5c5d66a310f3108c3c83d578"), "num" : 4 }
{ "_id" : ObjectId("5c5d66a310f3108c3c83d579"), "num" : 5 }
{ "_id" : ObjectId("5c5d66a310f3108c3c83d57a"), "num" : 6 }
{ "_id" : ObjectId("5c5d66a310f3108c3c83d57b"), "num" : 7 }
{ "_id" : ObjectId("5c5d66a310f3108c3c83d57c"), "num" : 8 }
{ "_id" : ObjectId("5c5d66a310f3108c3c83d57d"), "num" : 9 }
{ "_id" : ObjectId("5c5d66a310f3108c3c83d57e"), "num" : 10 }
{ "_id" : ObjectId("5c5d66a310f3108c3c83d57f"), "num" : 11 }
{ "_id" : ObjectId("5c5d66a310f3108c3c83d580"), "num" : 12 }
{ "_id" : ObjectId("5c5d66a310f3108c3c83d581"), "num" : 13 }
{ "_id" : ObjectId("5c5d66a310f3108c3c83d582"), "num" : 14 }
{ "_id" : ObjectId("5c5d66a310f3108c3c83d583"), "num" : 15 }
{ "_id" : ObjectId("5c5d66a310f3108c3c83d584"), "num" : 16 }
{ "_id" : ObjectId("5c5d66a310f3108c3c83d585"), "num" : 17 }
{ "_id" : ObjectId("5c5d66a310f3108c3c83d586"), "num" : 18 }
{ "_id" : ObjectId("5c5d66a310f3108c3c83d587"), "num" : 19 }
Type "it" for more
> 

Here we can see only 20 documents, it will depend upon the platform, next documents can be seen using "it" as suggested at the end of the result

> it
{ "_id" : ObjectId("5c5d66a310f3108c3c83d588"), "num" : 20 }
{ "_id" : ObjectId("5c5d66a310f3108c3c83d589"), "num" : 21 }
.....
{ "_id" : ObjectId("5c5d66a310f3108c3c83d59b"), "num" : 39 }
Type "it" for more
> 

Now try finding details for employees with emp_id 2000 from collection tech_large

> db.tech_large.find({emp_id: 2000});
{ "_id" : ObjectId("5c5d69e110f3108c3c83e514"), "emp_id" : 2000 }
> 

Find details of num value greater than 1991 

> db.techno_col.find({num: {"$gt" :1991}});
{ "_id" : ObjectId("5c5d66a510f3108c3c83dd3c"), "num" : 1992 }
{ "_id" : ObjectId("5c5d66a510f3108c3c83dd3d"), "num" : 1993 }
{ "_id" : ObjectId("5c5d66a510f3108c3c83dd3e"), "num" : 1994 }
{ "_id" : ObjectId("5c5d66a510f3108c3c83dd3f"), "num" : 1995 }
{ "_id" : ObjectId("5c5d66a510f3108c3c83dd40"), "num" : 1996 }
{ "_id" : ObjectId("5c5d66a510f3108c3c83dd41"), "num" : 1997 }
{ "_id" : ObjectId("5c5d66a510f3108c3c83dd42"), "num" : 1998 }
{ "_id" : ObjectId("5c5d66a510f3108c3c83dd43"), "num" : 1999 }
> 

Now try finding the employees between emp_id 5000 and 5009. 

> db.tech_large.find({emp_id : {"$gt" : 5000, "$lt" : 5009}});
{ "_id" : ObjectId("5c5d69e410f3108c3c83f0cd"), "emp_id" : 5001 }
{ "_id" : ObjectId("5c5d69e410f3108c3c83f0ce"), "emp_id" : 5002 }
{ "_id" : ObjectId("5c5d69e410f3108c3c83f0cf"), "emp_id" : 5003 }
{ "_id" : ObjectId("5c5d69e410f3108c3c83f0d0"), "emp_id" : 5004 }
{ "_id" : ObjectId("5c5d69e410f3108c3c83f0d1"), "emp_id" : 5005 }
{ "_id" : ObjectId("5c5d69e410f3108c3c83f0d2"), "emp_id" : 5006 }
{ "_id" : ObjectId("5c5d69e410f3108c3c83f0d3"), "emp_id" : 5007 }
{ "_id" : ObjectId("5c5d69e410f3108c3c83f0d4"), "emp_id" : 5008 }
> 

Use of $and and $or operators :

As I have only typical documents in the collection, results may not differ, but these operators will be a handful

> db.techno_col.find({$and: [{_id : ObjectId("5c5d66a410f3108c3c83d8ea")}, {num : 886}]})
{ "_id" : ObjectId("5c5d66a410f3108c3c83d8ea"), "num" : 886 }
> 
> db.techno_col.find({$or: [{_id : ObjectId("5c5d66a410f3108c3c83d8ea")}, {num : 887}]})
{ "_id" : ObjectId("5c5d66a410f3108c3c83d8ea"), "num" : 886 }
{ "_id" : ObjectId("5c5d66a410f3108c3c83d8eb"), "num" : 887 }
>

In next article of MongoDB will be learn Indexing and explain plan.
  • Share This:  
  •  Facebook
  •  Twitter
  •  Instagram
  •  Pin
  •  linkedin
  •  reddit
Email ThisBlogThis!Share to XShare to Facebook
Newer Post Older Post Home

0 comments:

Post a Comment

Author

Atikh Shaikh
View my complete profile

Categories

  • MongoDB (18)
  • Oracle 12c (30)
  • Oracle12cR2 New Feature (3)
  • PostgreSQL (21)
  • RMAN (10)
  • Snowflake (8)
  • mysql (23)
  • oracle (74)

Blog Archive

  • ►  2018 (38)
    • ►  November (25)
    • ►  December (13)
  • ▼  2019 (33)
    • ►  January (15)
    • ▼  February (6)
      • PostgreSQL : pg_hba. conf configuration file
      • MongoDB : Creating a Large Document
      • MongoDB : Indexing and explain Plan
      • MongoDB : Basic Administration
      • Oracle : Restore points
      • Configure and Use of Flash Recovery Area
    • ►  March (2)
    • ►  April (5)
    • ►  May (5)
  • ►  2020 (5)
    • ►  April (1)
    • ►  May (2)
    • ►  July (2)
  • ►  2021 (8)
    • ►  June (3)
    • ►  July (3)
    • ►  August (1)
    • ►  December (1)
  • ►  2022 (33)
    • ►  May (3)
    • ►  June (10)
    • ►  July (3)
    • ►  August (4)
    • ►  September (8)
    • ►  October (3)
    • ►  November (2)
  • ►  2023 (14)
    • ►  February (1)
    • ►  April (5)
    • ►  May (2)
    • ►  June (1)
    • ►  September (1)
    • ►  October (1)
    • ►  December (3)
  • ►  2024 (5)
    • ►  January (2)
    • ►  March (3)
  • ►  2025 (7)
    • ►  March (1)
    • ►  April (3)
    • ►  May (2)
    • ►  August (1)
  • ►  2026 (1)
    • ►  January (1)

Popular Posts

  • Oracle Dataguard Broker Configuration (DGMGRL)
    Data Guard Broker is a command-line interface that makes managing primary and standby databases easy. DBA can use a single command to switch...
  • Snowflake : Using snowsql for snowflake database
    A snowflake data warehouse is the latest addition to the trending database technology, In this article, we will be discussing snowsql, a com...
  • ORACLE : Creating a new pluggable database using PDB$SEED
    As a database administrator, you might come across creating a pluggable database, here is the method to create a pluggable database (PDB), F...
  • ORA-29283: invalid file operation: unexpected "LFI" error (1509)[29437]
    I was trying to export the schema in my windows PC, it got stuck with below error    C:\Users\shaik\Videos\technodba exp>expdp userid...
  • Table Dropped in Oracle Database ? Worry not, we can recover it
    There are a couple of options we can use to recover dropped tables in 19c Oracle database version  Restore table from Recycle Bin (assume ...

Labels

oracle Oracle 12c mysql PostgreSQL MongoDB oracle 19c Oracle23c oracle19c Orale PDB-CDB oracle12c python AWS Oracle ASM Virtualbox pluggable database storage engine

Pages

  • Disclaimer
  • Privacy Policy

Follow TechnoDBA

Copyright © Atikh's DBA blog | Powered by Blogger