I have developed an app with local version of community MongoDB (v4.4). Now I've connected to Mongo Atlas (it's running v 4.2).
I'm running a watch command to create a changestream.
While with my local setup everything works, with atlas I get an error
MongoError: Error validating $match value for change streams. err=ns field has bson.D value that is not string or valid MongoDb RegEx: Error parsing value [{$in [somestring1 somestring2 somestring3]}] to RegEx: Must specify $regex field
The query, resp. watch pipeline is
Database.watch([
{
"$match":{
"ns.coll":{
"$in":["somestring1","somestring2","somestring3"]
}
}
}
],
{fullDocument:"updateLookup"}
)
I've changed it to $or alternative:
Database.watch([
{
"$match":{
"$or":[
{"ns.coll":"somestring1"},
{"ns.coll":"somestring2"},
{"ns.coll":"somestring3"}
]
}
}
],
{fullDocument:"updateLookup"}
)
This works correctly.
The Database is a connection from nodejs driver. And the error is an immediate response from atlas server after calling the watch.
The error has also this properties:
ok: 0,
code: 8000,
codeName: 'AtlasError'
What's the problem? What can/should I do about it?
While the workaround works, I guess it is less performant.
Related
I'm trying to setup the new fullDocumentBeforeChange feature introduced in MongoDB 6.0 , however I always get the following error:
MongoServerError: featureFlagClusterWideConfig not enabled
When trying to enable the feature from mongosh directly, I get the following error:
MongoServerError: Cannot set cluster parameter, gFeatureFlagClusterWideConfig is not enabled
I have followed these steps to enable this feature.
My NodeJS code looks like this:
client.db(database).admin().command({
setClusterParameter: { changeStreamOptions: { preAndPostImages: { expireAfterSeconds: 100 } } },
})
I'm running mongo in a replica set.
I'm getting an error for mongo query in mongo version 3.6.22 error as follows
MongoError: arguments to $lookup must be strings, let: { profileIds:
"$ProfileIDs" } is type object
But this same query works fine in mongo version 4.4.3 enterprise, and the ProfileIDs are String
3.6 does not support let in $lookup. You need to write your query differently.
when I run any query containing $expr operation against Embedded Mongo I get the following error:
UncategorizedMongoDbException: Query failed with error code 2 and error message 'unknown top level operator: $expr' on server
The command runs fine against my local instance of mongo.
This is the version of embedded mongo I'm using: testCompile('de.flapdoodle.embed:de.flapdoodle.embed.mongo:2.1.1')
This is the query for reference:
Criteria.where("$expr").ne(Arrays.asList("$val.a", "$val.b"))
Found it.
flapdoodle was downloading a version of Mongodb that didn't have that feature by default.
You can override the default version by specifying the following in your
src/test/resources/application.properties
spring.mongodb.embedded.version=3.6.4
spring.mongodb.embedded.features=SYNC_DELAY,NO_HTTP_INTERFACE_ARG,ONLY_WITH_SSL
Mongo aggregation framework has some changes in version 3.6 Earlier aggregation queries with monger are not working even when we pass :cursor {} as an option. Is there any workaround or do we have to wait for the next monger release?. The error we get is specified below
MongoCommandException Command failed with error 9: 'The 'cursor' option is required, except for aggregate with the explain argument' on server localhost:27017. The full response is { "ok" : 0.0, "errmsg" : "The 'cursor' option is required, except for aggregate with the explain argument", "code" : 9, "codeName" : "FailedToParse" } com.mongodb.connection.ProtocolHelper.getCommandFailureException (ProtocolHelper.java:115)
by OSt advice, I could run monger aggregation sample with codes below.
(mc/aggregate db coll
[{"$project" {:subtotal {"$multiply" ["$quantity", "$price"]}
:_id "$state"}}]
:cursor {:batch-size 0})
thanks!
According to mongo db spec, cursor became a required field in some cases. So you should provide it through monger API. It is not a problem in monger, it is a breakable change in mongo db API.
I have the following mongo versions
db version v2.4.1
MongoDB shell version: 2.4.1,
and
db version v2.2.1-rc1, pdfile version 4.5,
MongoDB shell version: 2.2.1-rc1
installed on 64-bit windows 7 machine.
I have a collection having 10001000 (10 million+) records, when I use V 2.4.1 to aggregate, it fails with the following
error:
Fatal error in CALL_AND_RETRY_2
Allocation failed - process out of memory
However when I use V 2.2.1-rc1, to aggregate the same collection, it works fine and gives result in around 1 minute.
Sample document of the collection that is being aggregated:
{
"_id" : ObjectId("516bdd1c39b10c722792e007"),
"f1" : 10000010,
"f2" : 10000000,
"key" : 0
}
Aggregation Command:
{$group: {"_id": "$key", total: {$sum: "$f1"}}}
Command used to populate records:
for(var i = 10011000; i < 10041000; ++i)
{
db.testp.insert({"f1": i+10, "f2": i, "key": i%1000})
}
How much memory do you have? Could it be the $group is taking up more than 10% of available memory and causing the error? See the aggregation documentation on memory for cumulative operators.
edit 1:
Out of interest - does the aggregation work outside the shell? eg calling it from a driver.
I have seen similar v8 errors and as the shell was updated to v8 in 2.4 Theres a chance it could be that.
edit 2:
If the resulting array is too big in the shell then that can also trigger the error: see SERVER-8859. To work around you might need to run multiple aggregations, either by doing a $match early on to limit the working set or even a $skip and $limit to paginate through the result set.
I tried your aggregation with 10,070,999 docs on 2.4.1 on a mac and didn't get the error