where can I find any mongodb change stream example for php ?
not tailable cursor on a "capped collection", I'd need to "watch" a modifiable collection from php
the environment is WAMP php 7.2 windows
where can I find any mongodb change stream example for php ?
not tailable cursor on a "capped collection", I'd need to "watch" a modifiable collection from php
further to that, where could there be any examples of regex "match" of subset of _id docs to be watched ?$regex = new MongoDB\BSON\Regex ( '^'.$substring);// _id starting with "substring"$query = new MongoDB\Driver\Query( array('_id' => $regex) );$cursor = $manager->executeQuery($collection, $query); // Query the collection for a subset of _id sperhaps it should be specified as a "pipeline" to the watch (blocking) method ?thank you for any clues.
due to my specific requirements I'm not using mongo supplied object ids as _id but am using my own strings as (indexed) key, that said, could you make any educated guess whether anything like this may be feasible in order to filter to a subset of docs, without modifying the _id clearly, i.e. read only filter :$pipeline =array(array('$match' => array('_id' => '^0FFC')));$changeStream = $collection->watch($pipeline);where I am aiming to restrict to only _id starting with substring '0FFC' say, thank you for any clue.
Il giorno martedì 5 novembre 2019 17:32:35 UTC+1, Jeremy Mikola ha scritto:On Tue, Nov 5, 2019 at 9:10 AM Guglielmo Fanini <g.f...@gmail.com> wrote:further to that, where could there be any examples of regex "match" of subset of _id docs to be watched ?$regex = new MongoDB\BSON\Regex ( '^'.$substring);// _id starting with "substring"$query = new MongoDB\Driver\Query( array('_id' => $regex) );$cursor = $manager->executeQuery($collection, $query); // Query the collection for a subset of _id sperhaps it should be specified as a "pipeline" to the watch (blocking) method ?thank you for any clues.The structure of documents returned by iterating a change stream (i.e. cursor-like object returned by watch() methods) is described on the Change Events page in the MongoDB manual. The PHP library docs also link to this in the "See Also" section in each page for the various watch() methods.Note that the top-level _id field in a change event document is a resume token, which is used internally to continue iteration after an error. Modify Change Stream Output in the MongoDB manual advises users not to modify/remove that field via a pipeline stage (e.g. $project). Recent versions of the server will raise an error if they detect a pipeline stage attempting to modify the field.The actual _id of the changed document can be found under the change event's "documentKey._id" field. That is probably want you want to match on, and you can do so using the $match pipeline stage.Details about regex matches are discussed in the $regex operator docs in the MongoDB manual. The PHP library also has examples in its CRUD: Regular Expressions tutorial page. The MongoDB manual notes differences between using the $regex query operator and a BSON regex object (although the manual refers to that as /pattern/ syntax, since it's written from the POV of the MongoDB shell). And important thing to note is that MongoDB's query engine only supports matching regular expressions against string types. Assuming your document _id values are ObjectIds, I don't think you'll be able to match them directly with a regex pattern.That said, if you're using the aggregation framework you can insert a $project stage in the pipeline (accepted by both aggregate and watch methods) that converts ObjectIds values to a string, and then do a $match between the newly converted string value and a regex pattern. See https://stackoverflow.com/a/51231012/162228 for an existing discussion on that subject (pertaining just to ObjectId to string conversion within a pipeline).
--
You received this message because you are subscribed to the Google Groups "mongodb-user"
group.
For other MongoDB technical support options, see: https://docs.mongodb.com/manual/support/
---
You received this message because you are subscribed to the Google Groups "mongodb-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mongodb-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/mongodb-user/128aa18e-53ea-40d9-ae83-aab19a6ce8ee%40googlegroups.com.
To unsubscribe from this group and stop receiving emails from it, send an email to mongod...@googlegroups.com.
thanks for that, it works, because I was getting really weird out of memory errors attempting to "match" just _id,
perhaps you might wish to put any such example on the official documentation website of php lib ?
To unsubscribe from this group and stop receiving emails from it, send an email to mongodb-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/mongodb-user/a5823ee9-7486-4f31-a431-1e9c111660ca%40googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/mongodb-user/a5823ee9-7486-4f31-a431-1e9c111660ca%40googlegroups.com.
Of course more explanations would be helpful if possbile.
Another question : can the watch() cursor be kept open indefinitely ? or must it be reopened when the op log rolls over ?After a while I get EXCEPTION: cannot resume stream; the resume token was not found. {_data: "825DC99861000001C32B022C0100296E5A1004DFE455B4382D414D9CB41F8710A12E0C463C5F6964003C3032393332303431000004"}
any clue what this may mean when watching a constantly updating (not removed) collection :IterateWatchCursor EXCEPTION:MongoDB\Driver\Exception\CommandException: CollectionScan died due to position in capped collection being deleted. Last seen record id: RecordId(6761473611439013897) - 136I am unsure where this exception is thrown :
next() seems to try to resume()
so it's not resumable ? I need to recreate the watch cursor ?thank you
On Wed, Nov 20, 2019 at 11:11 PM Guglielmo Fanini <g.f...@gmail.com> wrote:any clue what this may mean when watching a constantly updating (not removed) collection :IterateWatchCursor EXCEPTION:MongoDB\Driver\Exception\CommandException: CollectionScan died due to position in capped collection being deleted. Last seen record id: RecordId(6761473611439013897) - 136I am unsure where this exception is thrown :This error message originates in the CollectionScan::doRestoreStateRequiresCollection() function in the server. Based on some references to the message in the server's JIRA project, it looks like this is an expected error if the change stream iteration does not keep up with the oplog. We previously discussed an issue with failing to keep up with the oplog earlier in this thread ("the resume token was not found" error message), so I believe the error here is just a different manifestation of the same issue. In this case, you're seeing the error attempting to issue a getMore command whilst iterating the change stream cursor.Your later replies suggest that you identified next() as the source of this exception. In the future, the getTrace() or getTraceAsString() methods on the Exception class should be useful for determining the origin of any PHP exception.
So that CappedPositionLost (code 136) is not resumable, and I'd need to reopen the watch on the collection ?