This can be reproduced by starting a standalone mongod with featureFlagSBE and then running the following script:
(function() { "use strict"; const coll = db.c; coll.drop(); assert.commandWorked(coll.insert({str: ""})); const pipeline = [{"$project": {"a": {"$indexOfCP": [{$literal: ""}, "$str", NumberLong(1)]}, "_id": 0}}]; const resultsWithSbe = coll.aggregate(pipeline).toArray(); function setForceClassic(val) { assert.commandWorked(db.adminCommand({setParameter: 1, internalQueryForceClassicEngine: val})); } const resultsWithoutSbe = (function() { try { setForceClassic(true); return coll.aggregate(pipeline).toArray(); } finally { setForceClassic(false); } }()); assert.eq(resultsWithSbe, resultsWithoutSbe); }());
This should fail with a message such as the following:
MongoDB server version: 5.0.0-alpha0 uncaught exception: Error: [[ { "a" : -1 }, { "a" : -1 } ]] != [[ { "a" : 0 }, { "a" : 0 } ]] are not equal : doassert@src/mongo/shell/assert.js:20:14 assert.eq@src/mongo/shell/assert.js:179:9 @repro.js:30:1 @repro.js:1:2 failed to load: repro.js exiting with code -3
With SBE on, $indexOfCP is returning -1, presumably to indicate that the needle string is not found at any position in the haystack string. With SBE off, the classic engine returns 0. I haven't yet dug into exactly