@@ -913,6 +913,112 @@ void describe('MongoDB Compatibility Tests', () => {
913
913
} ) ) ,
914
914
) ;
915
915
} ) ;
916
+
917
+ void it ( 'should limit number of results in both PostgreSQL and MongoDB' , async ( ) => {
918
+ const pongoCollection = pongoDb . collection < User > ( 'limitCollection' ) ;
919
+ const mongoCollection = mongoDb . collection < User > ( 'limitCollection' ) ;
920
+ const docs = [
921
+ { name : 'David' , age : 40 } ,
922
+ { name : 'Eve' , age : 45 } ,
923
+ { name : 'Frank' , age : 50 } ,
924
+ ] ;
925
+
926
+ await pongoCollection . insertOne ( docs [ 0 ] ! ) ;
927
+ await pongoCollection . insertOne ( docs [ 1 ] ! ) ;
928
+ await pongoCollection . insertOne ( docs [ 2 ] ! ) ;
929
+
930
+ await mongoCollection . insertOne ( docs [ 0 ] ! ) ;
931
+ await mongoCollection . insertOne ( docs [ 1 ] ! ) ;
932
+ await mongoCollection . insertOne ( docs [ 2 ] ! ) ;
933
+
934
+ const pongoDocs = await pongoCollection . find ( { } , { limit : 2 } ) . toArray ( ) ;
935
+ const mongoDocs = await mongoCollection . find ( { } , { limit : 2 } ) . toArray ( ) ;
936
+
937
+ assert . strictEqual ( pongoDocs . length , 2 ) ;
938
+ assert . strictEqual ( mongoDocs . length , 2 ) ;
939
+
940
+ assert . deepStrictEqual (
941
+ pongoDocs . map ( ( d ) => ( { name : d . name , age : d . age } ) ) ,
942
+ docs . slice ( 0 , 2 ) . map ( ( d ) => ( { name : d . name , age : d . age } ) ) ,
943
+ ) ;
944
+
945
+ assert . deepStrictEqual (
946
+ pongoDocs . map ( ( d ) => ( { name : d . name , age : d . age } ) ) ,
947
+ mongoDocs . map ( ( d ) => ( { name : d . name , age : d . age } ) ) ,
948
+ ) ;
949
+ } ) ;
950
+
951
+ void it ( 'should skip number of results in both PostgreSQL and MongoDB' , async ( ) => {
952
+ const pongoCollection = pongoDb . collection < User > ( 'skipCollection' ) ;
953
+ const mongoCollection = mongoDb . collection < User > ( 'skipCollection' ) ;
954
+ const docs = [
955
+ { name : 'David' , age : 40 } ,
956
+ { name : 'Eve' , age : 45 } ,
957
+ { name : 'Frank' , age : 50 } ,
958
+ ] ;
959
+
960
+ await pongoCollection . insertOne ( docs [ 0 ] ! ) ;
961
+ await pongoCollection . insertOne ( docs [ 1 ] ! ) ;
962
+ await pongoCollection . insertOne ( docs [ 2 ] ! ) ;
963
+
964
+ await mongoCollection . insertOne ( docs [ 0 ] ! ) ;
965
+ await mongoCollection . insertOne ( docs [ 1 ] ! ) ;
966
+ await mongoCollection . insertOne ( docs [ 2 ] ! ) ;
967
+
968
+ const pongoDocs = await pongoCollection . find ( { } , { skip : 1 } ) . toArray ( ) ;
969
+ const mongoDocs = await mongoCollection . find ( { } , { skip : 1 } ) . toArray ( ) ;
970
+
971
+ assert . strictEqual ( pongoDocs . length , 2 ) ;
972
+ assert . strictEqual ( mongoDocs . length , 2 ) ;
973
+
974
+ assert . deepStrictEqual (
975
+ pongoDocs . map ( ( d ) => ( { name : d . name , age : d . age } ) ) ,
976
+ docs . slice ( 1 , 3 ) . map ( ( d ) => ( { name : d . name , age : d . age } ) ) ,
977
+ ) ;
978
+
979
+ assert . deepStrictEqual (
980
+ pongoDocs . map ( ( d ) => ( { name : d . name , age : d . age } ) ) ,
981
+ mongoDocs . map ( ( d ) => ( { name : d . name , age : d . age } ) ) ,
982
+ ) ;
983
+ } ) ;
984
+
985
+ void it ( 'should use limit and skip parameters to paginate results in both PostgreSQL and MongoDB' , async ( ) => {
986
+ const pongoCollection = pongoDb . collection < User > ( 'limitSkipCollection' ) ;
987
+ const mongoCollection = mongoDb . collection < User > ( 'limitSkipCollection' ) ;
988
+ const docs = [
989
+ { name : 'David' , age : 40 } ,
990
+ { name : 'Eve' , age : 45 } ,
991
+ { name : 'Frank' , age : 50 } ,
992
+ ] ;
993
+
994
+ await pongoCollection . insertOne ( docs [ 0 ] ! ) ;
995
+ await pongoCollection . insertOne ( docs [ 1 ] ! ) ;
996
+ await pongoCollection . insertOne ( docs [ 2 ] ! ) ;
997
+
998
+ await mongoCollection . insertOne ( docs [ 0 ] ! ) ;
999
+ await mongoCollection . insertOne ( docs [ 1 ] ! ) ;
1000
+ await mongoCollection . insertOne ( docs [ 2 ] ! ) ;
1001
+
1002
+ const pongoDocs = await pongoCollection
1003
+ . find ( { } , { limit : 1 , skip : 1 } )
1004
+ . toArray ( ) ;
1005
+ const mongoDocs = await mongoCollection
1006
+ . find ( { } , { limit : 1 , skip : 1 } )
1007
+ . toArray ( ) ;
1008
+
1009
+ assert . strictEqual ( pongoDocs . length , 1 ) ;
1010
+ assert . strictEqual ( mongoDocs . length , 1 ) ;
1011
+
1012
+ assert . deepStrictEqual (
1013
+ pongoDocs . map ( ( d ) => ( { name : d . name , age : d . age } ) ) ,
1014
+ docs . slice ( 1 , 2 ) . map ( ( d ) => ( { name : d . name , age : d . age } ) ) ,
1015
+ ) ;
1016
+
1017
+ assert . deepStrictEqual (
1018
+ pongoDocs . map ( ( d ) => ( { name : d . name , age : d . age } ) ) ,
1019
+ mongoDocs . map ( ( d ) => ( { name : d . name , age : d . age } ) ) ,
1020
+ ) ;
1021
+ } ) ;
916
1022
} ) ;
917
1023
918
1024
void describe ( 'Handle Operations' , ( ) => {
0 commit comments