@@ -24,36 +24,25 @@ private DataFlow::Node getADollarWhereProperty(API::Node queryArg) {
24
24
*/
25
25
private module MongoDB {
26
26
/**
27
- * Gets an access to `mongodb.MongoClient`.
27
+ * Gets an access to `mongodb.MongoClient` or a database.
28
+ *
29
+ * In Mongo version 2.x, a client and a database handle were the same concept, but in 3.x
30
+ * they were separated. To handle everything with a single model, we treat them as the same here.
28
31
*/
29
- private API:: Node getAMongoClient ( ) {
32
+ private API:: Node getAMongoClientOrDatabase ( ) {
30
33
result = API:: moduleImport ( "mongodb" ) .getMember ( "MongoClient" )
31
34
or
32
- // The callback parameter is either a MongoClient or Db depending on the mongodb package version,
33
- // but we just model it as both.
34
- result = getAMongoDbCallback ( ) .getParameter ( 1 )
35
- }
36
-
37
- /** Gets an API-graph node that refers to a `connect` callback. */
38
- private API:: Node getAMongoDbCallback ( ) {
39
- result = getAMongoClient ( ) .getMember ( "connect" ) .getLastParameter ( )
40
- }
41
-
42
- /**
43
- * Gets an API-graph node that may refer to a MongoDB database connection.
44
- */
45
- private API:: Node getAMongoDb ( ) {
46
- result = getAMongoClient ( ) .getMember ( "db" ) .getReturn ( )
35
+ result = getAMongoClientOrDatabase ( ) .getMember ( "db" ) .getReturn ( )
47
36
or
48
- // The callback parameter is either a MongoClient or Db depending on the mongodb package version,
49
- // but we just model it as both.
50
- result = getAMongoDbCallback ( ) .getParameter ( 1 )
37
+ result = getAMongoClientOrDatabase ( ) .getMember ( "connect" ) .getLastParameter ( ) .getParameter ( 1 )
51
38
}
52
39
53
40
/** Gets a data flow node referring to a MongoDB collection. */
54
41
private API:: Node getACollection ( ) {
55
42
// A collection resulting from calling `Db.collection(...)`.
56
- exists ( API:: Node collection | collection = getAMongoDb ( ) .getMember ( "collection" ) .getReturn ( ) |
43
+ exists ( API:: Node collection |
44
+ collection = getAMongoClientOrDatabase ( ) .getMember ( "collection" ) .getReturn ( )
45
+ |
57
46
result = collection
58
47
or
59
48
result = collection .getParameter ( 1 ) .getParameter ( 0 )
0 commit comments