[SERVER-50544] Filtering on collection on deployment level change stream Created: 26/Aug/20  Updated: 27/Aug/20  Resolved: 27/Aug/20

Status: Closed
Project: Core Server
Component/s: Querying
Affects Version/s: None
Fix Version/s: None

Type: Question Priority: Major - P3
Reporter: Joydip Datta Assignee: Unassigned
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Participants:

 Description   

I am trying to setup a deployment level change stream with a pipeline filter on collection name using MongoDB java SDK. Here is the code snippet.

   List<Bson> pipeline = Collections.singletonList(Aggregates.match(Filters.or(
        Filters.eq("namespace", "db1.c1"),
        Filters.eq("namespace", "db1.c2"))));
 
    client.watch(pipeline)
        .fullDocument(FullDocument.UPDATE_LOOKUP).cursor()
        .forEachRemaining(doc -> {
          System.out.println(doc);
        });

 But this query does not match any document. Following variations of the pipeline document does not work either.

    List<Bson> pipeline =
    Collections.singletonList(Aggregates.match(Filters.or(
      Document.parse("{'namespace': 'db1.c1'}"),
      Document.parse("{'namespace': 'db1.c2'}")))); 

Surprisingly pipeline works on other fields of the changestream document. For example, this works:

     List<Bson> pipeline = Collections
     .singletonList(Aggregates.match(Filters.and(
     Document.parse("{'fullDocument.seq': 4}"),
     Filters.in("operationType", Arrays.asList("insert")))));

I am not sure why this would be the case. I would appreciate any help in this regard.



 Comments   
Comment by Eric Sedor [ 27/Aug/20 ]

jdatta@imanisdata.com this looks like it is expected behavior given the format of change stream documents. Just briefly, the namespace is stored in parts as "ns.db" and "ns.coll", not as "namespace".

If you need further assistance troubleshooting, I encourage you to ask our community by posting on the MongoDB Developer Community Forums or on Stack Overflow with the mongodb tag.

Sincerely,
Eric

Generated at Thu Feb 08 05:22:56 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.