sails: Cannot find all entries greater than "id" with sails-mongo

Sails version: 1.1.0 Node version: 8.14.0 NPM version: 6.4.1 DB adapter name: sails-mongo DB adapter version: 1.0.1 Operating system: Windows 10


For pagination, I am have my frontend send the “id” of the last entry. So I can fetch all entries “after” this id. I do this like this:

In Mongo I’m trying to fetch all entries with an id greater than 5c5da8cde14566339029260e. I’m doing this: Blah.find({ id: { '>': '5c5da8cde14566339029260e' }}) but its not returning any results.

In my config/models.js I have made the update to id: { type: 'string', columnName: '_id' },. Here is my models.js file - https://gist.github.com/Noitidart/2fb4893551deccc638a28bc9cd4bbe8e

In Gitter, I asked for help and he thinks I am facing problems with ObjectId implicit conversions by waterline. Would be awesome if I could search by > id in mongo. This gurantees proper “cursor” paging.

About this issue

  • Original URL
  • State: open
  • Created 8 years ago
  • Comments: 15 (5 by maintainers)

Most upvoted comments

Try below solution

const ObjectId = require('mongodb').ObjectId;
MyModel.find({
  _id: { '>': ObjectId('5c5da8cde14566339029260e') }
})