You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// Import the MongoClient from the mongodb packageimport{MongoClient}from'mongodb';// Connection URL and Database Nameconsturl='mongodb://localhost:27017';constdbName='myDatabase';asyncfunctionrun(){// Create a new MongoClientconstclient=newMongoClient(url);try{// Connect to the MongoDB serverawaitclient.connect();console.log('Connected successfully to MongoDB');// Select the databaseconstdb=client.db(dbName);// Select the collectionconstcollection=db.collection('myCollection');// Query the collectionconstdocuments=awaitcollection.find({}).toArray();console.log('Documents retrieved:',documents);}catch(err){console.error('An error occurred:',err);}finally{// Close the connectionawaitclient.close();console.log('Connection closed');}}// Run the functionrun();
rule:
# we want to highlight the usage of our imported module# so the usage is what we are actually going to match on.# to check against the import we will traverse from the usage all the way to the root of the doc# and then down to the import statement# the usagekind: identifierpattern: $MOD# its relationship to the rootinside:
stopBy: endkind: program# and back down to the import statementhas:
stopBy: end # we allow going multiple levels deep though we expect imports to be children of the rootkind: import_statement# and deeper into the import statement looking for the matching identifierhas:
stopBy: endkind: import_specifierpattern: $MOD # same pattern as the usage is enforced here
The text was updated successfully, but these errors were encountered:
The text was updated successfully, but these errors were encountered: