[mongodb] nested array/object support for PullOperator (#40056)

This commit is contained in:
Jordan Stout
2019-11-08 14:49:20 -08:00
committed by Nathan Shively-Sanders
parent a5d3d40734
commit 29b43a06a2
2 changed files with 7 additions and 2 deletions
+3 -1
View File
@@ -1208,7 +1208,7 @@ export type PushOperator<TSchema> = ({
};
export type PullOperator<TSchema> = ({
readonly [key in KeysOfAType<TSchema, any[]>]?: Unpacked<TSchema[key]> | QuerySelector<Unpacked<TSchema[key]>>;
readonly [key in KeysOfAType<TSchema, any[]>]?: Partial<Unpacked<TSchema[key]>> | ObjectQuerySelector<Unpacked<TSchema[key]>>;
} &
NotAcceptedFields<TSchema, any[]>) & {
readonly [key: string]: QuerySelector<any> | any;
@@ -1365,6 +1365,8 @@ export type RootQuerySelector<T> = {
[key: string]: any;
};
export type ObjectQuerySelector<T> = T extends object ? {[key in keyof T]?: QuerySelector<T[key]> } : QuerySelector<T>;
export type Condition<T> = MongoAltQuery<T> | QuerySelector<MongoAltQuery<T>>;
export type FilterQuery<T> = {
+4 -1
View File
@@ -7,7 +7,8 @@ async function run() {
const db = client.db('test');
interface SubTestModel {
field: string;
field1: string;
field2: string;
}
// test with collection type
@@ -106,6 +107,8 @@ async function run() {
buildUpdateQuery({ $pull: { fruitTags: { $in: ['a'] } } });
buildUpdateQuery({ $pull: { 'dot.notation': 1 } });
buildUpdateQuery({ $pull: { 'subInterfaceArray.$[]': { $in: ['a'] } } });
buildUpdateQuery({ $pull: { subInterfaceArray: { field1: 'a' } }});
buildUpdateQuery({ $pull: { subInterfaceArray: { field1: { $in: ['a'] } } }});
buildUpdateQuery({ $push: { fruitTags: 'a' } });
buildUpdateQuery({ $push: { fruitTags: { $each: ['a'] } } });