Is it possible to repeat the mongo cursor twice?

In other words, is there a way to rewind it to the beginning?

EDIT

I use mongo and pymongo shell.

+6
source share
3 answers

The Ruby API has a rewind! method rewind! that does exactly what you want.

The Python API also has a cursor.rewind() method.

The PHP API also has a cursor.rewind() method.

However, neither the Java API nor C ++ have a rewind method. Everything can be found on the official API page.

+14
source

You can use cursor.reset();

For PHP: $cursor->reset();

then run your foreach($cursorData as $data) anytime after a reset.

+1
source

The cursor in pymongo has a .rewind() method, you can refer to the sample code from the previous question with the answer that applies .

The mongo api native shell, however, does not provide such a method; see the help() method in the DBQuery object prototype. :

 > db.collection.find().help() find() modifiers .sort( {...} ) .limit( n ) .skip( n ) .count() - total # of objects matching query, ignores skip,limit .size() - total # of objects cursor would return, honors skip,limit .explain([verbose]) .hint(...) .showDiskLoc() - adds a $diskLoc field to each returned object Cursor methods .forEach( func ) .map( func ) .hasNext() .next() 
0
source

Source: https://habr.com/ru/post/911674/


All Articles