Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8398545
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T21:04:47+00:00 2026-06-09T21:04:47+00:00

In my find function. The parameter ‘item’ is always Null. I wonder if there

  • 0

In my find function. The parameter ‘item’ is always Null. I wonder if there are some problems about inserting or finding of my code. How should I solve it??

    var express = require('express');
    var routes = require('./routes');
    var socket = require('socket.io');
    var fs = require('fs');
    var app = module.exports = express.createServer();
    var Server = require('mongodb').Server,
        Db = require('mongodb').Db,
        Connection = require('mongodb').Connection;
    var host = 'localhost';
    var port = Connection.DEFAULT_PORT;
    var db = new Db('node-mongo-examples', new Server(host, port, {}), {native_parser:false});
    var id ;


    db.open(function(err, db) {
        //console.log('opened');   
        app.listen(3000); 

    });

    db.collection('locations', function(err, collection) {
         var object= ({'word':'TEST'},{'word':'HELL'},{'img':'terr'});
         collection.insert(object,  function(err, result) {
            console.log(result);
            id = object._id;
            collection.find({'word':'TEST'}).toArray(function(err, items){

                    console.log('item' +items);// <-- The item is always NULL
            });  


        });
     });

Then I change My code to….

But it still have the error about “Cannot call method collection of null.”

    db.open(function(err, db) {
            db.collection('locations', function(err, collection) {
                var object= ({'word':'TEST'},{'word':'HELL'},{'img':'terr'});
            collection.insert(object,  function(err, result) {
                console.log(result);
                id = object._id;
                collection.find({'word':'TEST'}).toArray(function(err, items){
                    if(err)
                        console.log(err);
                    else
                        console.log('item' +items);
                });  


                });
        });
        app.listen(3000); 

    });
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T21:04:48+00:00Added an answer on June 9, 2026 at 9:04 pm

    This line:

    var object= ({'word':'TEST'},{'word':'HELL'},{'img':'terr'});
    

    use console.log(object); and see exactly what you are inserting into MongoDB. This code is equivalent to

    var object = {'img':'terr'};
    

    That’s why you always get null – you don’t insert the document you are looking for.

    If you want to pass multiple documents, then use array:

    var object= [{'word':'TEST'},{'word':'HELL'},{'img':'terr'}];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I use this function to find any installed application . But the parameter InstallLocation
I am trying to find out where a callback function came from, but e.parameter.source
Is there any way to find particular C language function's input and output parameters
I want to send array into eq function as parameter. Like that: $(this).find('tr').not(':eq(array)').each(function(){ });
I need a mathematical function/formula/expression to take a number as parameter and find the
In php mail() function, how can I send attachments? I didn't find parameter to
that required in first parameter of FindWindow function? there long time,I seen this information
I read the next answer about passing function as parameter . Still, I don't
I have a Find function in order to find an element from a BST
I trying to find function in PHP that can output the binary data. The

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.