Meteor MongoDB Error - mongodb

I have this issue with my meteor app. When I run this query on my chrome console, It returns the expected data
Questions.find({}, {sort:{commentLength: -1}})
but when I run it in the console as db.questions.find({}, {sort:{commentLength: -1}})
it returns this error
error: {
"$err" : "Can't canonicalize query: BadValue Unsupported projection option: sort: { commentLength: -1.0 }",
"code" : 17287
}
Why does this error happen? Thanks

sort has a different syntax when executed in a mongodb shell. Try this instead:
db.questions.find().sort({commentLength: -1})

Related

Spark/MongoDB connector with $or pipeline syntax

I'm trying to request a MongoDB collection using Spark with the mongo-spark-connector. Here is the code :
val document = Document.parse("{$or: [{key1:\"A\", key2:\"500\"}, {key1:\"A\", key2:\"100\"}] }")
val mongoDf = mongoCollectionRdd.withPipeline(Seq(document)).toDF(mongoCollectionSchema)
But I get the following error :
com.mongodb.MongoCommandException: Command failed with error 40324 (Location40324): 'Unrecognized pipeline stage name: '$or'' on server hostname.fr:27017.
I ran the query through the mongo shell and the execution is fine and I get the expected result. Here are the versions of the different components :
Scala : 2.12.11
Spark : 3.2.0
MongoDB : 4.2.17
Any ideas ?

when i try to run the updateOne method in mongoDB , i get this error uncaught exception: SyntaxError: illegal character :

The Query:
db.products.updateOne(
{"name":"pen"},
{$set : { "stock" : 32}},
)
I got this error:
uncaught exception: SyntaxError: illegal character :
Try to change $set with "$set". Also, enter the code in the question instead of putting images.

mongo db error - SyntaxError: missing ; before statement

when i try to run this command on cmd.
mongo test --eval 'db.testcollection.find({ createdate: {$gte: ISODate("2020-07-28 10:08:37.579Z"),$lt: ISODate("2020-08-04 13:42:40.975Z")}}, {place:1, _id:0}).forEach(function(x) { print(x.place); })'
it throws this error
MongoDB server version: 4.0.5
2020-08-06T13:33:49.336+0530 E QUERY [js] SyntaxError: missing ; before statement #(shell eval):1:19
i try to add a semicolon at the end. it still throws same error.
mongo test --eval 'db.testcollection.find({ createdate: {$gte: ISODate("2020-07-28 10:08:37.579Z"),$lt: ISODate("2020-08-04 13:42:40.975Z")}}, {place:1, _id:0}).forEach(function(x) { print(x.place); });'
Error is at line 1, column 19. So placing ; at the end will not solve the issue.
Could you use
mongo --eval 'db.testcollection.find({ createdate: {$gte: ISODate("2020-07-28 10:08:37.579Z"),$lt: ISODate("2020-08-04 13:42:40.975Z")}}, {place:1, _id:0}).forEach(function(x) { print(x.place); })' test
test is the db name where testcollection is present.

Issue with mongodb document limit

I am using mongodb 3.0.2 and when I run "top" command :
> db.runCommand( { top: 1 } )
I got the following error message:
2015-06-01T16:36:52.886+0900 E QUERY Error: error: {
"$err" : "BSONObj size: 46060490 (0x2BED3CA) is invalid. Size must be between 0 and 16793600(16MB)",
"code" : 10334
}
at Error ()
at DBQuery.next (src/mongo/shell/query.js:259:15)
at DBCollection.findOne (src/mongo/shell/collection.js:189:22)
at DB.runCommand (src/mongo/shell/db.js:58:41)
at (shell):1:4 at src/mongo/shell/query.js:259
It means that I can't monitor any longer, doesn't it? Can you guys show me the way out, please.
Some additional info:
DB size: 143.996GB - with wiredtiger enable.
Replication set enable.
No profiling.

MongoDB Access Error

Getting error something of this sort when accessing MongoDB. Any clue?
QueryFailure flag was unauthorized db:monza lock type:-1 client:10.173.78.216 (response was { "$err" : "unauthorized db:monza lock type:-1 client:10.173.78.216", "code" : 10057 }).