Skip to content

Commit a42bb7f

Browse files
committed
Update README.md
1 parent d951586 commit a42bb7f

File tree

1 file changed

+0
-216
lines changed

1 file changed

+0
-216
lines changed

README.md

Lines changed: 0 additions & 216 deletions
Original file line numberDiff line numberDiff line change
@@ -117,13 +117,6 @@ Connecting MongoDB Cloud using MongoDB Compass
117117
<b><a href="#">↥ back to top</a></b>
118118
</div>
119119

120-
## Q. ***Mention the command to insert a document in a database called company and collection called employee?***
121-
122-
```js
123-
use company;
124-
db.employee.insert( { name: "John", email: "john.k@gmail.com" } )
125-
```
126-
127120
## Q. ***What are Indexes in MongoDB?***
128121

129122
Indexes support the efficient execution of queries in MongoDB. Without indexes, MongoDB must perform a collection scan, i.e. scan every document in a collection, to select those documents that match the query statement. If an appropriate index exists for a query, MongoDB can use the index to limit the number of documents it must inspect.
@@ -866,100 +859,6 @@ MongoDB transactions can exist only for relatively short time periods. By defau
866859
<b><a href="#">↥ back to top</a></b>
867860
</div>
868861
869-
## Q. ***How to combine data from multiple collections into one collection?***
870-
871-
**$lookup**
872-
873-
Performs a left outer join to an unsharded collection in the same database to filter in documents from the “joined” collection for processing. To each input document, the `$lookup` stage adds a new array field whose elements are the matching documents from the “joined” collection. The `$lookup` stage passes these reshaped documents to the next stage.
874-
875-
**Syntax**
876-
877-
```js
878-
{
879-
$lookup:
880-
{
881-
from: <collection to join>,
882-
localField: <field from the input documents>,
883-
foreignField: <field from the documents of the "from" collection>,
884-
as: <output array field>
885-
}
886-
}
887-
```
888-
889-
<div align="right">
890-
<b><a href="#">↥ back to top</a></b>
891-
</div>
892-
893-
## Q. ***Find objects between two dates MongoDB?***
894-
895-
Operator `$gte` and `$lt` is used to find objects between two dates in MongoDB.
896-
897-
**Example**: Creating a collection
898-
899-
```js
900-
>db.order.insert({"OrderId":1,"OrderAddrees":"US","OrderDateTime":ISODate("2020-02-19")};
901-
WriteResult({ "nInserted" : 1 })
902-
903-
>db.order.insert({"OrderId":2,"OrderAddrees":"UK","OrderDateTime":ISODate("2020-02-26")};
904-
WriteResult({ "nInserted" : 1 })
905-
```
906-
907-
Display all documents from the collection using `find()` method.
908-
909-
```js
910-
> db.order.find().pretty();
911-
912-
// Output
913-
{
914-
"_id" : ObjectId("5c6c072068174aae23f5ef57"),
915-
"OrderId" : 1,
916-
"OrderAddrees" : "US",
917-
"OrderDateTime" : ISODate("2020-02-19T00:00:00Z")
918-
}
919-
{
920-
"_id" : ObjectId("5c6c073568174aae23f5ef58"),
921-
"OrderId" : 2,
922-
"OrderAddrees" : "UK",
923-
"OrderDateTime" : ISODate("2020-02-26T00:00:00Z")
924-
}
925-
```
926-
927-
Here is the query to find objects between two dates:
928-
929-
```js
930-
> db.order.find({"OrderDateTime":{ $gte:ISODate("2020-02-10"), $lt:ISODate("2020-02-21") }
931-
}).pretty();
932-
933-
934-
// Output
935-
{
936-
"_id" : ObjectId("5c6c072068174aae23f5ef57"),
937-
"OrderId" : 1,
938-
"OrderAddrees" : "US",
939-
"OrderDateTime" : ISODate("2020-02-19T00:00:00Z")
940-
}
941-
```
942-
943-
<div align="right">
944-
<b><a href="#">↥ back to top</a></b>
945-
</div>
946-
947-
## Q. ***How to query MongoDB with "like"?***
948-
949-
```js
950-
db.users.insert({name: 'paulo'})
951-
db.users.insert({name: 'patric'})
952-
db.users.insert({name: 'pedro'})
953-
954-
db.users.find({name: /a/}) //like '%a%'
955-
db.users.find({name: /^pa/}) //like 'pa%'
956-
db.users.find({name: /ro$/}) //like '%ro'
957-
```
958-
959-
<div align="right">
960-
<b><a href="#">↥ back to top</a></b>
961-
</div>
962-
963862
## Q. ***Should I normalize my data before storing it in MongoDB?***
964863
965864
Data used by multiple documents can either be embedded (denormalized) or referenced (normalized). Normalization, which is increasing the complexity of the schema by splitting tables into multiple smaller ones to reduce the data redundancy( 1NF, 2NF, 3NF).
@@ -1180,16 +1079,6 @@ If you are running a 64-bit build of MongoDB, there is virtually no limit to sto
11801079
<b><a href="#">↥ back to top</a></b>
11811080
</div>
11821081
1183-
## Q. ***Mention the command to check whether you are on the master server or not?***
1184-
1185-
```js
1186-
db.isMaster()
1187-
```
1188-
1189-
<div align="right">
1190-
<b><a href="#">↥ back to top</a></b>
1191-
</div>
1192-
11931082
## Q. ***Can one MongoDB operation lock more than one database?***
11941083
11951084
Yes. Operations like `db.copyDatabase()`, `db.repairDatabase()`, etc. can lock more than one databases involved.
@@ -1528,86 +1417,6 @@ MongoDB compresses the files by:
15281417
<b><a href="#">↥ back to top</a></b>
15291418
</div>
15301419
1531-
## Q. ***Is it possible to update MongoDB field using value of another field?***
1532-
1533-
The aggregate function can be used to update MongoDB field using the value of another field.
1534-
1535-
**Example**
1536-
1537-
```js
1538-
db.collection.<update method>(
1539-
{},
1540-
[
1541-
{"$set": {"name": { "$concat": ["$firstName", " ", "$lastName"]}}}
1542-
]
1543-
)
1544-
```
1545-
1546-
<div align="right">
1547-
<b><a href="#">↥ back to top</a></b>
1548-
</div>
1549-
1550-
## Q. ***How to check if a field contains a substring?***
1551-
1552-
The `$regex` operator can be used to check if a field contains a string in MongoDB.
1553-
1554-
```js
1555-
db.users.findOne({"username" : {$regex : ".*some_string.*"}});
1556-
```
1557-
1558-
<div align="right">
1559-
<b><a href="#">↥ back to top</a></b>
1560-
</div>
1561-
1562-
## Q. ***How to find document with array that contains a specific value?***
1563-
1564-
Populate the inventory collection
1565-
1566-
```js
1567-
db.inventory.insertMany([
1568-
{ item: "journal", qty: 25, tags: ["blank", "red"], dim_cm: [ 14, 21 ] },
1569-
{ item: "notebook", qty: 50, tags: ["red", "blank"], dim_cm: [ 14, 21 ] },
1570-
{ item: "paper", qty: 100, tags: ["red", "blank", "plain"], dim_cm: [ 14, 21 ] },
1571-
{ item: "planner", qty: 75, tags: ["blank", "red"], dim_cm: [ 22.85, 30 ] },
1572-
{ item: "postcard", qty: 45, tags: ["blue"], dim_cm: [ 10, 15.25 ] }
1573-
]);
1574-
```
1575-
1576-
To query if the array field contains at least one element with the specified value, use the filter { `<field>`: `<value>` } where `<value>` is the element value.
1577-
1578-
```js
1579-
db.inventory.find( { tags: "red" } )
1580-
```
1581-
1582-
<div align="right">
1583-
<b><a href="#">↥ back to top</a></b>
1584-
</div>
1585-
1586-
## Q. ***How to find MongoDB records where array field is not empty?***
1587-
1588-
```js
1589-
db.inventory.find({ pictures: { $exists: true, $ne: [] } })
1590-
```
1591-
1592-
<div align="right">
1593-
<b><a href="#">↥ back to top</a></b>
1594-
</div>
1595-
1596-
## Q. ***How to get the last N records from find?***
1597-
1598-
```js
1599-
// Syntax
1600-
db.<CollectionName>.find().sort({$natural:-1}).limit(value)
1601-
1602-
1603-
// Example
1604-
db.employee.find().sort({$natural:-1}).limit(100)
1605-
```
1606-
1607-
<div align="right">
1608-
<b><a href="#">↥ back to top</a></b>
1609-
</div>
1610-
16111420
## Q. ***Explain relationships in MongoDB?***
16121421
16131422
Relationships in MongoDB are used to specify how one or more documents are related to each other. In MongoDB, the relationships can be modelled either by Embedded way or by using the Reference approach. These relationships can be of the following forms:
@@ -1738,31 +1547,6 @@ Capped collections restrict updates to the documents if the update results in in
17381547
<b><a href="#">↥ back to top</a></b>
17391548
</div>
17401549
1741-
## Q. ***How to remove a field completely from a MongoDB document?***
1742-
1743-
How do I remove words completely from all the documents in this collection?
1744-
1745-
```js
1746-
{
1747-
name: 'book',
1748-
tags: {
1749-
words: ['abc','123'], // <-- remove it comletely
1750-
lat: 33,
1751-
long: 22
1752-
}
1753-
}
1754-
```
1755-
1756-
**Answer**
1757-
1758-
```js
1759-
db.example.update({}, {$unset: {words: 1}}, false, true);
1760-
```
1761-
1762-
<div align="right">
1763-
<b><a href="#">↥ back to top</a></b>
1764-
</div>
1765-
17661550
## Q. ***What is splitting in MongoDB?***
17671551
## Q. ***Explain what is horizontal scalability in mongodb?***
17681552

0 commit comments

Comments
 (0)