Skip to content

Commit 202b337

Browse files
committed
Update mongodb-code.md
1 parent cc3afe9 commit 202b337

File tree

1 file changed

+36
-2
lines changed

1 file changed

+36
-2
lines changed

mongodb-code.md

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@ db.isMaster()
2323

2424
## Q. ***How to combine data from multiple collections into one collection?***
2525

26-
**$lookup**
26+
**$lookup:**
2727

2828
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.
2929

30-
**Syntax**
30+
**Syntax:**
3131

3232
```js
3333
{
@@ -353,6 +353,10 @@ The operation results in the following document:
353353
}
354354
```
355355
356+
<div align="right">
357+
<b><a href="#">↥ back to top</a></b>
358+
</div>
359+
356360
## Q. ***How to join 3 or more collections in MongoDB?***
357361
358362
Let's say we have 3 hypothetical collections in MongoDB: customers, orders, and orderItems.
@@ -491,3 +495,33 @@ db.customers.aggregate([
491495
<div align="right">
492496
<b><a href="#">↥ back to top</a></b>
493497
</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
516+
db.myCollection.validate({ })
517+
518+
// perform a full validation of collection
519+
db.myCollection.validate( { full: true } )
520+
521+
// repair collection
522+
db.myCollection.validate( { repair: true } )
523+
```
524+
525+
<div align="right">
526+
<b><a href="#">↥ back to top</a></b>
527+
</div>

0 commit comments

Comments
 (0)