diff --git a/index.js b/index.js index 78fe0266a624c8b0bb92c0b2d79844da87811f77..6c1c85dc4a2031ce78f8383018f8591fbb066be9 100644 --- a/index.js +++ b/index.js @@ -1,42 +1,28 @@ - -const { MongoClient, ServerApiVersion } = require('mongodb'); -const uri = "mongodb+srv://wrvr:qqqq258369@cluster0.kmggvco.mongodb.net/?retryWrites=true&w=majority"; - -// Create a MongoClient with a MongoClientOptions object to set the Stable API version -const client = new MongoClient(uri, { - serverApi: { - version: ServerApiVersion.v1, - strict: true, - deprecationErrors: true, +var axios = require('axios'); +var data = JSON.stringify({ + "collection": "mycollection", + "database": "mydatabase", + "dataSource": "Cluster0", + "projection": { + "_id": 1 } }); - -async function run() { - try { - // Connect the client to the server (optional starting in v4.7) - await client.connect(); - // Send a ping to confirm a successful connection - await client.db("admin").command({ ping: 1 }); - console.log("Pinged your deployment. You successfully connected to MongoDB!"); - - // Get a reference to the database - const db = client.db('mydatabase'); - - // Get a reference to the collection - const collection = db.collection('mycollection'); - - // Insert a document - const resultInsert = await collection.insertOne({ name: 'Alice3', age: 30 }); - console.log(`Inserted ${resultInsert.insertedCount} documents into the collection`); - - // Find documents - const resultFind = await collection.find({ age: { $gt: 25 } }).toArray(); - console.log(`Found ${resultFind.length} documents that match the query`); - console.log(resultFind); - - } finally { - // Ensures that the client will close when you finish/error - await client.close(); - } -} -run().catch(console.dir); + +var config = { + method: 'post', + url: 'https://ap-southeast-1.aws.data.mongodb-api.com/app/data-jmriv/endpoint/data/v1/action/findOne', + headers: { + 'Content-Type': 'application/json', + 'Access-Control-Request-Headers': '*', + 'api-key': 'RddbxMZlXN9uX3qKx39q58CoRWjkiyb8qihoOo5bLAnVVpmi5hmKeMHKQVvNfb8O', + }, + data: data +}; + +axios(config) + .then(function (response) { + console.log(JSON.stringify(response.data)); + }) + .catch(function (error) { + console.log(error); + });