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

  • Home
  • SEARCH
  • 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 7652153
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T11:41:36+00:00 2026-05-31T11:41:36+00:00

Here is my data structure. [{ name: David, lastname: , }, { name: Angela

  • 0

Here is my data structure.

[{
"name": "David",
"lastname": "",
},
{
"name": "Angela"
}]

“lastname” is sometimes present and sometimes not and sometime is “”.

I want to get all rows that have lastname not equal to “”. But this does not work. It returns both the rows when lastname is “” and when lastname is not present at all. in the example above I want to only get the David node.

db.collection.find( {"lastname": {"$ne": ""}} )
  • 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-05-31T11:41:37+00:00Added an answer on May 31, 2026 at 11:41 am
    db.collection.find({"lastname" : {"$exists" : true, "$ne" : ""}})
    

    In the mongo shell (id’s omitted to save space)

    > db.collection.find()
      { "name" : "Angela" }
      { "name" : "David", "lastname" : "" }
      { "name" : "Kyle",  "lastname" : "Test" }
      { "name" : "John",  "lastname" : null }
    
    > db.collection.find({"lastname" : {"$exists" : true, "$ne" : ""}})
      { "name" : "Kyle", "lastname" : "Test" }
      { "name" : "John",  "lastname" : null }
    

    In case you also want to filter out matches against null values you need to adjust the criteria as follows (we can also get rid of $exists as “$ne”: null takes care of this)

    > db.collection.find({$and:[{"lastname": {"$ne": null}}, {"lastname": {"$ne": ""}}]})
      { "name" : "Kyle", "lastname" : "Test" }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here is a table structure (e.g. test): Field Name Data Type id BIGINT (20)
Here is my data structure alt text http://luvboy.co.cc/images/db.JPG when i try this sql select
last time I asked how to populate a data structure here . Now I
Is there a .NET data structure I could use for bidirectional lookup? Here's the
I'm having difficulty with pages that does not show the updated data immediately Here's
ex: <a><strike>example data in here</strike></a> I want everything inside the a tag, to the
i have a php question, how can i get all the data from the
I want to write a function that parses a (theoretically) unknown XML data structure
Given the following data structure var things = [{ name: thing1, sex: male}, {
I want to design a data structure with the following properties: Accessible as a

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.