Skip to content

Commit

Permalink
docs: Add advance subdocument query documentation (#6344)
Browse files Browse the repository at this point in the history
Example for querying subdocuments and array of subdocuments
  • Loading branch information
Ibcs16 committed Jul 6, 2020
1 parent 8e2d97d commit 60711c2
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions docs/mongodb.md
Expand Up @@ -266,6 +266,35 @@ const timber = await userRepository.find({
});
```

Querying subdocuments

```typescript
import {getMongoRepository} from "typeorm";

const userRepository = getMongoRepository(User);
// Query users with education Tree School
const users = await userRepository.find({
where: {
'profile.education': { $eq: "Tree School"}
}
});
```

Querying Array of subdocuments

```typescript
import {getMongoRepository} from "typeorm";

const userRepository = getMongoRepository(User);
// Query users with photos of size less than 500
const users = await userRepository.find({
where: {
'photos.size': { $lt: 500}
}
});

```


Both `MongoEntityManager` and `MongoRepository` contain lot of useful MongoDB-specific methods:

Expand Down

0 comments on commit 60711c2

Please sign in to comment.