You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: mongodb-code.md
+36-2Lines changed: 36 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -23,11 +23,11 @@ db.isMaster()
23
23
24
24
## Q. ***How to combine data from multiple collections into one collection?***
25
25
26
-
**$lookup**
26
+
**$lookup:**
27
27
28
28
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.
29
29
30
-
**Syntax**
30
+
**Syntax:**
31
31
32
32
```js
33
33
{
@@ -353,6 +353,10 @@ The operation results in the following document:
353
353
}
354
354
```
355
355
356
+
<div align="right">
357
+
<b><a href="#">↥ back to top</a></b>
358
+
</div>
359
+
356
360
## Q. ***How to join 3 or more collections in MongoDB?***
357
361
358
362
Let's say we have 3 hypothetical collections in MongoDB: customers, orders, and orderItems.
@@ -491,3 +495,33 @@ db.customers.aggregate([
491
495
<div align="right">
492
496
<b><a href="#">↥ back to top</a></b>
493
497
</div>
498
+
499
+
## Q. ***How to validate data in mongodb?***
500
+
501
+
`db.collection.validate(<documents>)` validates a collection. The method scans a collection data and indexes for correctness and returns the result.
502
+
503
+
**Syntax:**
504
+
505
+
```js
506
+
db.collection.validate( {
507
+
full:<boolean>, // Optional
508
+
repair:<boolean>// Optional, added in MongoDB 5.0
509
+
} )
510
+
```
511
+
512
+
**Example:**
513
+
514
+
```js
515
+
// validate a collection using the default validation setting
0 commit comments