skip to Main Content

From a mongo collection I have a deleted field, this field is null or has a date, I am trying to get only the documents whose deleted is with date, or in other words, to eliminate those whose deleted: null, for this I am using ramda but it only returns all the documents.

 , deletedFilesList () {
  return reject(equals(null))(this.rows);
}

Any idea??

2

Answers


  1. For a Ramda approach, you’ll need a predicate that looks at a given prop:

    return filter(propSatisfies(is(String), 'deleted'))(this.rows);
    
    Login or Signup to reply.
  2. Reject all items which their deleted prop is equal to null:

    const { reject, propEq } = R
    
    const fn = reject(propEq(null, 'deleted'))
    
    const rows = [{ id: 1, deleted: null }, { id: 2, deleted: Date.now() }, { id: 3, deleted: null }];
    
    const result = fn(rows)
    
    console.log(result)
    <script src="https://cdnjs.cloudflare.com/ajax/libs/ramda/0.29.0/ramda.min.js" integrity="sha512-5x/n+aOg68Z+O/mq3LW2pC2CvEBSgLl5aLlOJa87AlYM1K8b8qsZ7NTHLe3Hu56aS2W0rgEgVCFA3RM12IXAGw==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search