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 9012077
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T02:54:14+00:00 2026-06-16T02:54:14+00:00

Check out the following query: db.models.findOne({ value.userId: { $ne: null } }, { value.userId:1}).value.userId

  • 0

Check out the following query:

 db.models.findOne({ "value.userId": { $ne: null } }, { "value.userId":1}).value.userId == null

This says:

  1. Find a record that has a non-null user id field
  2. Return the user id in the result
  3. Compare that value to null

Since we’re returning only records without null values, comparing the result of that to null should always return false. However, this always returns true.

If I just do the .findOne(…) and print that instead of doing the comparison, I get:

{ "_id": 4, "value": { "userId": null }

Anyone have a clue what’s going on here?

EDIT: the “type” of this field is apparently 6 – not 10, which is what a null should be.
EDIT2: apparently type 6 is “undefined” – not sure why it prints null…

  • 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-16T02:54:15+00:00Added an answer on June 16, 2026 at 2:54 am

    Well the issue here is when you try to print an undefined value, MongoDB prints null rather than issuing you an error.

    See this example: –

    > db.foo.save({"amount": undefined})
    > db.foo.find({"amount": {$ne: null}})
    { "_id" : ObjectId("50d0d3a1511dd1035f01c636"), "amount" : null }
    

    So, as you are saying, the type of userId is 6, which is for undefined, so it prints null. Also, it is $ne: null, so it is matched too.

    See this link: – http://realprogrammer.wordpress.com/2012/11/04/null-undefined-nan-and-missing-property-goto-considered-harmful-part-2/


    However, if you see the same behaviour with null, you will get the desired result: –

    > db.foo.save({"amount": null})
    > db.foo.findOne({"amount": {$ne: null}}) 
    null
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Check out this jsbin . I have a form with a custom button that
I need help to find out a query to check the availability of rooms
Please check out the following query. The SQL isn't as bad as it looks.
I recently asked this question: Dynamically Query a Database to check for value And
check out the following test: http://binks.knobbits.org/webgl/texture3.html It's a simple test of cube textures. It
Please check out the following func and its output void main() { Distance d1;
Please check out my following code... public enum LogType { Debug, Info, Warn, Error,
I am trying to check the following and all throw an out of bounds
Check out http://fube.ca in any browser but Firefox and you'll see that the cloud
Check out this pic of my SQL 2008 Management Configuration screen for TCP: I

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.