I try to use Ramda for deleted the files with file deleted=null

53 views Asked by At

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??

3

There are 3 answers

0
AKX On BEST ANSWER

For a Ramda approach, you'll need a predicate that looks at a given prop:

return filter(propSatisfies(is(String), 'deleted'))(this.rows);
0
Ori Drori On

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>

0
Hitmands On

Also Ramda has isNil or isNotNil, therefore you could use something like:

R.filter(R.propSatisfies(R.isNil, 'deleted'), documents)

Although a bit outside of your original ask, if you are working with Mongo, it could be beneficial to add this condition as part of your database query to optimise your program...

db.collection('files').find({
  deleted: { $exists: false }
});