Getting NULL data from collection from MongoDB Atlas
NickName:Akash Kulkarni Ask DateTime:2019-04-26T07:40:28

Getting NULL data from collection from MongoDB Atlas

I have connected my code to MongoDB Atlas using Mongoose... even though the collection has a data in it its shows null in response.


I want to know the exact issue and troubleshoot it, because the collection has the data required

Collection details are in this image:

Enter image description here

1. Connectivity Code -
const mongoose = require('mongoose')
const uri = "mongodb+srv://<user>:<password>@cluster0-3awwl.mongodb.net/";
mongoose.connect(uri, {
    dbName: 'bing_bot'
}).catch((e) => {
    console.log('Database connectivity error ', e)
})

2.Model-
const mongoose = require('mongoose')

const Student = mongoose.model('student', {
    StudentName: {
        type:String
    },
    Contact: {
        type:String
    },
    Email: {
        type:String
    },
    BNo: {
        type:String
    },
    Year: {
        type:String
    }
})
 module.exports = Student`enter code here`

3. Retrieve data -
Student.findById(_id).then((data) => {
        console.log('data: ', data)})


4. Using MongoCLient

const uri = "mongodb+srv://<user>:<password>@cluster0-3awwl.mongodb.net/bing_bot"
MongoClient.connect(uri, function(err, client) {
   if(err) {
        console.log('Error occurred while connecting to MongoDB Atlas...\n', err);
   }
   console.log('Connected...');
   const collection = client.db("bing_bot").collection("student");
   // perform actions on the collection object
   collection.findOne({
       "StudentName": "Test"
   }).then((d) => {
       console.log('data: ', d)
   })

   const data = collection.find()
   console.log('data:1 ', data)
   client.close();
});

Copyright Notice:Content Author:「Akash Kulkarni」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/55858975/getting-null-data-from-collection-from-mongodb-atlas

More about “Getting NULL data from collection from MongoDB Atlas” related questions

Getting NULL data from collection from MongoDB Atlas

I have connected my code to MongoDB Atlas using Mongoose... even though the collection has a data in it its shows null in response. I want to know the exact issue and troubleshoot it, because the

Show Detail

Fetching Sample Data from MongoDB Atlas with mongoose

As the title suggests, I am trying to fetch existing data that already exists inside MongoDB Atlas. The data comes from the mongoDB Atlas sample data, and I am using the sample_mflix database. I h...

Show Detail

MongoDB query returns null even though it is available in the collection after migrating from mlab to mongoDB atlas

I am migrating a database from Mlab to MongoDB Atlas. We had to upgrade the npm version of mongodb to 3.4.1 as the MongoDB atlas database version is 4.2.5. The connection function has been updated as

Show Detail

Azure Data Factory - delete data from a MongoDb (Atlas) Collection

I'm trying to use Azure Data Factory (V2) to copy data to a MongoDb database on Atlas, using the MongoDB Atlas connector but I have an issue. I want to do an Upsert but the data I want to copy has no

Show Detail

get data by id from mongoDb atlas data collection

I'm trying to get data by using id but I always get 500 internal error. It would be great help if someone help to find what error I have done to get request. I have done post request successfully and

Show Detail

nodejs could not console log data from mongodb atlas

nodejs connects to atlas succesfully but when i try to console log the data I get error const uri = "mongodb+srv://daww:[email protected]/admin" MongoClient.connect(uri,

Show Detail

How to import data from json file to mongodb atlas collection

I wanted to import data to my collection in mongodb atlas, and I was following the documentation: https://docs.mongodb.com/compass/beta/import-export/ but there is no "ADD DATA" and I don't know i...

Show Detail

unable to load whole data from mongodb atlas using python

I have a python program to fetch data in a collection from mongodb atlas but i am able to view only 10 data using the below python code from pymongo import MongoClient from pprint import pprint cli...

Show Detail

not accessing old data on mongodb atlas by Node application

I have not used mongodb atlas for 10 days. when I am trying to connect node application after 10 days into mongodb atlas returning blank array in find Query from Node application , when I inserted...

Show Detail

Cant read data from collection in MongoDB Atlas Trigger

New to MongoDB, very new to Atlas. I'm trying to set up a trigger such that it reads all the data from a collection named Config. This is my attempt: exports = function(changeEvent) { const mongo...

Show Detail