Compatibility issue for mongoDB 3.6 to add Validator - mongodb

{ "ok" : 0,
"errmsg" : "The featureCompatibilityVersion must be 3.6 to create a collection validator using 3.6 query features. See http://dochub.mongodb.org/core/3.6-feature-compatibility.",
"code" : 224,
"codeName" : "QueryFeatureNotAllowed"
}
The Above is the error in MongoDB.
Version - 3.6.2;
OS: Ubuntu 16.0.4;

Thank you guys for trying to answer my question but I solved the issue myself.
For me the solution was to execute the following command:
db.adminCommand({setFeatureCompatibilityVersion: "3.6"})

Related

Getting error message while replication database in mongodb windows

I am trying to replicate database in mongodb 4.0 in two different windows server. I followed all the steps of mongodb replication. While I was configuring the secondary database from primary through the below command
rsconf={_id:"myset",
members:[{_id:0,host:"PrimaryServerIP:27017"},{_id:1,host:"SecondaryServerIP:27017"}]}
Then while I was reconfiguring the rsconf through
rs.reconfig(rsconf)
I was getting the below error message
"Support for replication protocol version 0 was removed in MongoDB 4.0. Downgrade to MongoDB version 3.6 and upgrade your protocol version to 1 before upgrading your MongoDB version"
I tried to update the replication protocol by downgrading the MongoDB to 3.6 through the below command
rsconf = rs.conf()
rsconf.protocolVersion=1
rs.reconfig(rsconf)
But still getting the same error message. Is there any way to update the protocol version to 1 in mongodb 4.0.
Also I tried the same replication steps in mongodb 3.6 and it is working fine. Any help will be highly appreciated.
I had a similar issue and when I added protocolVersion to my new config it worked.
rsconf={
_id:"myset",
protocolVersion: NumberLong(1),
members:[{_id:0,host:"PrimaryServerIP:27017"},{_id:1,host:"SecondaryServerIP:27017"}]
}
I was initially having this issue trying to reset my rs config to blank so I could start over; I actually did this in the mongo shell
cfg = {
"_id" : "rs0",
"version" : 2,
"protocolVersion" : NumberLong(1),
"members" : [
{
"_id" : 0,
"host" : "myhost:27017"
}
]
}
rs.reconfig(cfg, {force:true})

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

Text search on mongodb 2.6 returning error

I'm using mongoDB 2.6 and the structure of my document is something like this:
{
"about": <about me>,
"_id" : <id>
}
I want to apply text search on about field. I did it using: db.user.ensureIndex({"about":"text"})
But when I run a search query: db.user.find({$text:{$search:"internet"}}) I get this error: error: { "$err" : "invalid operator: $search", "code" : 10068 } As per the documentation, text search is enabled on mongodb 2.6 by default. So what could be wrong? Earlier I had 2.2 installed on my machine. I recently downloaded 2.6 and I applied this index using 2.6 only.

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 error : invalid operator: $maxDistance

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!