mongodb error : invalid operator: $maxDistance - mongodb

MongoDB shell version: 2.1.0
$near operator works fine. But as I try (in mongodb shell and nodejs):
db.locations.find({loc: {$near:[50,50],$maxDistance:50}})
error: { "$err" : "invalid operator: $maxDistance" }
I tried upgrading mongodb (if you know an easy way to do this I would really really thank you as I had a lot of trouble with trying to shut down the server in order to replace the bin folder...)
Thank you!

upgrading mongodb solved the problem. 10x!

Related

Getting error for query in mongo 3.6.22 which works fine in 4.4.3 enterprise

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.

Type error on mongodb 3

When i try to insert data on mongodb 3 through command line it's showing following error
use video;
switched to db video
db.movies.insertOne({ "title": "Jaws", "year": 1975, "imdb": "tt0073195" });
2018-03-26T12:42:42.233+0530 E QUERY TypeError: Property 'insertOne' of object video.movies is not a function at (shell):1:11`
but video db also not created
Please help me to rectify this problem.
MongoDB supports db.collection.insertOne() from version 3.2, please check your mongodb version by using the mongo shell command
db.version()
References:
insertOne
version
Try with db.movies.insert instead of db.movies.insertOne and check If it's working fine. If it's working then your mongo version is less than 3.2. If not then share your mongoDb console Screenshot.

Unrecognized pipeline stage name: '$sample'

when I run this aggregation pipeline in Robomongo
db.getCollection('xyz').aggregate([{$match: {tyu: "asd", ghj: "qwe"}},
{$sample: {size: 5}}])
I receive this error:
assert: command failed: {
"errmsg" : "exception: Unrecognized pipeline stage name: '$sample'",
"code" : 16436,
"ok" : 0
I'm using mongodb ver 3.2.6 and since $sample is supported from 3.2 onward.
(https://docs.mongodb.com/manual/reference/operator/aggregation/sample/#pipe._S_sample)
Im a little confused as to why I receive this error message.
Maybe I'm just missing something small.
Thanks
As stated in the comments of the question. Mongo client had a version of 3.2.6 but Mongo db had a version of 3.0.6.
I used version() in the shell to get the client's version and
db.version() to get the DB's version.
ver 3.0.6 is too low to support $sample as stated in the mongo documentation
https://docs.mongodb.com/manual/reference/operator/aggregation/sample/#pipe._S_sample

MongoDB Java driver : no such cmd: aggregate

I am calling the MongoDB aggregate function in my code as :
AggregationOutput output = collection.aggregate( matchUserID, unwindF, matchFUsers,projection);
I have tested my code in my localhost, and it works perfect. When I am using the same in another DB (version 2.2.1), it gives this error :
com.mongodb.CommandResult$CommandFailure: command failed [aggregate]: { "serverUsed" : "<server address>" , "errmsg" : "no such cmd: aggregate" , "bad cmd" : { "aggregate" : .... }
Any clue why ?
Based on other answers I've seen to similar questions, it seems most likely that the server is not actually 2.2.1 as you believe.
How are you checking the server's version number?
From the shell, try this:
use admin
db.runCommand( {buildInfo: 1} )
figured out the error. I was using the 2.9 version on the MongoDB Java driver. When I upgraded it to 2.10, it worked perfectly. Thanks folks :)
I had the same error "no such cmd: aggregate", and I tried new version of mongodb 2.4,2.6 from default debian repositories and always receiving this error.
After that installed mongodb-org-server from mongo repo and it worked
http://docs.mongodb.org/manual/tutorial/install-mongodb-on-debian/

MongoDB unexpected token? when using $gte

I'm trying to get all documents that are greater than the current date, based on an 'end_date' field.
I'm using this:
db.collection.find({end_date: {$gte: new Date()}})
But I get a syntax error near `{end_date:'
Syntax seems to right - am I missing something?
Thank you!
This syntax works just fine for me:
derick#whisky:/tmp$ mongo
MongoDB shell version: 2.0.3
connecting to: test
> use demo
switched to db demo
> db.collection.find({end_date: {$gte: new Date()}})
>