find method is deprecated according to mongodb typings
Asked Answered
S

1

10

I currently have this call:

 const q = coll.find(query, {
    tailable: true,
    awaitData: true,
    oplogReplay: true,
    noCursorTimeout: true,
    numberOfRetries: Number.MAX_VALUE
  });

 return q.stream()

but my IDE warns me that this method on mongodb.Collection is deprecated:

enter image description here

Sure enough that's what the typings say. My question is - what is the long term solution here, what is the new way to make this same call?

Skyway answered 17/3, 2018 at 3:58 Comment(2)
note that this is find() on a Collection typeSkyway
Not sure why it's marked as deprecated in the typings, as it's not marked that way in the current API docs.Fredella
S
0

This seems to work, but is very verbose, and I am not sure if there is not a better way to do it:

 const q = coll.find(query)
  .addCursorFlag('tailable', true)
  .addCursorFlag('awaitData', false)
  .setCursorOption('numberOfRetries', Number.MAX_VALUE)
  .setCursorOption('tailableRetryInterval', 200)
  .addCursorFlag('noCursorTimeout', true)
  .addCursorFlag('oplogReplay', true);

note that the booleans, you need to use addCursorFlag, but the non-booleans need to use setCursorOption....seems weird/unnecessary.

Skyway answered 17/3, 2018 at 4:37 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.