From 60711c292422cb3b9cf3843613d4cb3977a8f124 Mon Sep 17 00:00:00 2001 From: IAGO BRAYHAM Date: Mon, 6 Jul 2020 18:29:22 -0300 Subject: [PATCH] docs: Add advance subdocument query documentation (#6344) Example for querying subdocuments and array of subdocuments --- docs/mongodb.md | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) 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: