Forum Discussion

msalvador's avatar
msalvador
Frequent Contributor
5 years ago

couldn't use mongo db drivers

Hi,
I downloaded both async and sync drivers from here https://mongodb.github.io/mongo-java-driver/3.12/driver-async/getting-started/installation/

I import my drivers in classpath(current project), I set java VM.

I use this code, but I couldn't see any obyect.


async function main() {
var MongoClient = require('mongodb')
var client = await MongoClient.connect('mongodb://string<1>:<string2>:10255/?ssl=true&appName=@user@')
var db = client.db('dlc-dev-cosmos')
var collection = db.collection('batteries')

var docs = await collection.find({}).limit(5).toArray()
//console.log(docs)
Log.Message(docs)
await client.close()
}

main();


Could help me

  • msalvador's avatar
    msalvador
    5 years ago

    MongoDB is a father root that contains all the libraries, in the javascript files, there is this call Require(.\<folder1>\<folder2>\xxx.js), and as I can see this not work importing in my project.

    I schift to another solution... java libraries, so I imported them in java bridge panel and use them.

  • TanyaYatskovska's avatar
    TanyaYatskovska
    SmartBear Alumni (Retired)

    Hi msalvador,

     

    Could you please clarify what you mean by "I couldn't see any object"? Where don't you see objects? If you are talking about Code Completion, I'm not sure if TestComplete shows objects from external libraries.

     

     

    • msalvador's avatar
      msalvador
      Frequent Contributor

      Hi tanya,

      What I wrote in my first post is not correct, now I clarify the situation.

      I download with this command: npm i –save mongodb     the mongo bd libraries(find in attachment, node_modules.zip).

      This libraries in filesystem have a tree structure.

      Then I run the function you find in the firt post, but it doesn't work.

      I tried to import libreries in my project but have a tree structure and don't work.

      I post a picture about my project explore

      I think you need some more infos, so please reply me

      • tristaanogre's avatar
        tristaanogre
        Esteemed Contributor

        If Mongdb is a javascript file, you need to actually add it to the project.  In your tree structure, I don't see it anywhere so calling requires("mongodb") won't work.