Rethinkdb: How To Select Where Row Doesn’t Have Field

A common query for data is selecting a document where a specific field does not exists. For example, if you are using a data structure where instead of actually deleting a document using .delete() you are setting a deletedAt property such as: deletedAt: '2020-01-02 12:12:30'.

Then every time you retrieved documents from your table, you would only want to select the documents that haven't been "deleted".

This wasn't immediately obvious to me how to do this, so here is how you would do the opposite of hasFields in RethinkDB to select a document that doe not have a specific field in JavaScript.

  .filter(function(user) {
    return user.hasFields('deletedAt').not()
  .run(conn, function(err, cursor) { 
    // Here are your non deleted documents

Small dog web development studio

View All Our Posts

Web application developers in western Washington, creating user centric web solutions for businesses of all shapes and sizes.

Our projects include ecommerce, event organization, user driven web applications and more.

Small Dog Studios, LLC. Small Dog Studios News