diff --git a/docs/mongodb.md b/docs/mongodb.md index ef27c103da..d3b26ed775 100644 --- a/docs/mongodb.md +++ b/docs/mongodb.md @@ -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: