Issue with geo index in mongoAtlas - mongodb

I´ve migrating my last mLab application with heroku to the new MongoAtlas platform. I found some issues when trying to create geo indexes for my collections.
Here is how I used to integrate the index in the mLab tool:
db.OpenDataMadrid.createIndex( {“location.coordinates” : “2dsphere” } )
db.OpenDataMadrid.createIndex( {“location.coordinates” : “2d” } )
db.BuscadoresDatasets.createIndex( {“location.coordinates” : “2dsphere” } )
db.BuscadoresDatasets.createIndex( {“location.coordinates” : “2d” } )
And now my new geo indexes for both collections are like this:
{
“mappings”: {
“dynamic”: true,
“fields”: {
“location”: {
“fields”: {
“coordinates”: [
{
“dynamic”: true,
“type”: “document”
},
{
“indexShapes”: true,
“type”: “geo”
}
]
},
“type”: “document”
}
}
}
}
But when I run the application and the $geoquery is done I receive the following error:
Exception: Query failed with error code 291 and error message 'error processing query: ns=gastrorecomendador.OpenDataMadrid limit=1Tree: GEONEAR field=location.coordinates maxdist=2 isNearSphere=0
2021-10-10T07:29:36.472781+00:00 app[web.1]: Sort: {}
2021-10-10T07:29:36.472781+00:00 app[web.1]: Proj: {}
2021-10-10T07:29:36.472787+00:00 app[web.1]: planner returned error :: caused by :: unable to find index for $geoNear query’ on server cluster0-shard-00-02.5ojd2.mongodb.net:27017
2021-10-10T07:29:36.585612+00:00 app[web.1]: Exception: Query failed with error code 291 and error message 'error processing query: ns=gastrorecomendador.OpenDataMadrid limit=300Tree: $and
2021-10-10T07:29:36.585620+00:00 app[web.1]: Type $eq “restaurant”
2021-10-10T07:29:36.585620+00:00 app[web.1]: Puntuacion $gt 3.5
2021-10-10T07:29:36.585621+00:00 app[web.1]: GEONEAR field=location.coordinates maxdist=250 isNearSphere=0
2021-10-10T07:29:36.585622+00:00 app[web.1]: Sort: {}
2021-10-10T07:29:36.585622+00:00 app[web.1]: Proj: {}
2021-10-10T07:29:36.585628+00:00 app[web.1]: planner returned error :: caused by :: unable to find index for $geoNear query’ on server cluster0-shard-00-02.5ojd2.mongodb.net:27017
Any help creating 2d and 2dphere indexes?
I’ve also try to create the index to the location variable instead of location.coordinates but it doesn’t work either.
Thanks in advance!

Related

Authentication fail when connecting to Atlas MongoDB

I have an error when connecting to the MongoDB Atlas database after I migrated the data from the old MLAB.
I have definitely setup the username and password correctly as in the documentation (obviously i replaced PASSWORD with my correct MLAB password:
var mongoURI = 'mongodb+srv://heroku_3kcdl3j9:PASSWORD#cluster-3kcdl3j9.auof1.mongodb.net/heroku_3kcdl3j9?retryWrites=true&w=majority';
I have migrated my database from MLAB to Atlas successfully set the correct Network access settings to 0.0.0.0 IP address. Setup the environment variable in Heroku.
I connect to the atlas database with this code, do I need some special options? (this code works with the old MLAB connection)
mongoose.connect(mongoURI,
// { config: { autoIndex: true } },
// { options : { ssl: true } },
function (error) {
if (error) console.error(error);
else console.log('mongo connected');
const con = new mongoose.mongo.Admin(mongoose.connection.db)
con.buildInfo( (err, mongoURI) => {
if(err){
throw err
}
// see the db version
// console.log('mongo db.version(): '+ db.version);
})
});
However, I still get this error, I don't know what I am doing wrong:
{ MongoError: authentication fail
at /Users/bensmith/Downloads/DocumentsDirNew/Scraper and API/diveapi/node_modules/mongodb-core/lib/topologies/replset.js:1462:15
at /Users/bensmith/Downloads/DocumentsDirNew/Scraper and API/diveapi/node_modules/mongodb-core/lib/connection/pool.js:868:7
at /Users/bensmith/Downloads/DocumentsDirNew/Scraper and API/diveapi/node_modules/mongodb-core/lib/connection/pool.js:844:20
at finish (/Users/bensmith/Downloads/DocumentsDirNew/Scraper and API/diveapi/node_modules/mongodb-core/lib/auth/scram.js:232:16)
at handleEnd (/Users/bensmith/Downloads/DocumentsDirNew/Scraper and API/diveapi/node_modules/mongodb-core/lib/auth/scram.js:242:7)
at /Users/bensmith/Downloads/DocumentsDirNew/Scraper and API/diveapi/node_modules/mongodb-core/lib/auth/scram.js:351:15
at /Users/bensmith/Downloads/DocumentsDirNew/Scraper and API/diveapi/node_modules/mongodb-core/lib/connection/pool.js:531:18
at process._tickCallback (internal/process/next_tick.js:61:11)
name: 'MongoError',
message: 'authentication fail',
errors:
[ { name: 'cluster-3kcdl3j9-shard-00-01.auof1.mongodb.net:27017',
err: [MongoError] },
{ name: 'cluster-3kcdl3j9-shard-00-00.auof1.mongodb.net:27017',
err: [MongoError] },
{ name: 'cluster-3kcdl3j9-shard-00-02.auof1.mongodb.net:27017',
err: [MongoError] } ],
[Symbol(mongoErrorContextSymbol)]: {} }
(node:47015) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 's' of undefined
at Admin.buildInfo (/Users/bensmith/Downloads/DocumentsDirNew/Scraper and API/diveapi/node_modules/mongodb/lib/admin.js:100:37)
at /Users/bensmith/Downloads/DocumentsDirNew/Scraper and API/diveapi/index.js:95:13
at $initialConnection.then.err (/Users/bensmith/Downloads/DocumentsDirNew/Scraper and API/diveapi/node_modules/mongoose/lib/connection.js:556:14)
at process._tickCallback (internal/process/next_tick.js:68:7)
(node:47015) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:47015) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
(node:47015) UnhandledPromiseRejectionWarning: MongoError: authentication fail
at /Users/bensmith/Downloads/DocumentsDirNew/Scraper and API/diveapi/node_modules/mongodb-core/lib/topologies/replset.js:1462:15
at /Users/bensmith/Downloads/DocumentsDirNew/Scraper and API/diveapi/node_modules/mongodb-core/lib/connection/pool.js:868:7
at /Users/bensmith/Downloads/DocumentsDirNew/Scraper and API/diveapi/node_modules/mongodb-core/lib/connection/pool.js:844:20
at finish (/Users/bensmith/Downloads/DocumentsDirNew/Scraper and API/diveapi/node_modules/mongodb-core/lib/auth/scram.js:232:16)
at handleEnd (/Users/bensmith/Downloads/DocumentsDirNew/Scraper and API/diveapi/node_modules/mongodb-core/lib/auth/scram.js:242:7)
at /Users/bensmith/Downloads/DocumentsDirNew/Scraper and API/diveapi/node_modules/mongodb-core/lib/auth/scram.js:351:15
at /Users/bensmith/Downloads/DocumentsDirNew/Scraper and API/diveapi/node_modules/mongodb-core/lib/connection/pool.js:531:18
at process._tickCallback (internal/process/next_tick.js:61:11)
(node:47015) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 2)
On the migration documentation from MLAB to ATLAS I can read:
Atlas servers always run with requireSSL and only accept TLS/SSL encrypted connections.
I can see that your ssl option is commented.
This is one problem.
The problem was it was something to do with the username and password. I believe there was an illegal character in the password. So I created another user with a better password and the server authenticated and logged in allowing it to connect.

Delete record based on condition from mongo database using jmeter

I am trying to delete the record from Mongo database using jmeter jsr223 groovy protocol but getting error.
Request:
--delete the records which is retrieved between the insert date
MongoCollection Collection = database.getCollection("TEST_COMM");
Collectionenter code here.deleteMany{
$and: [
{
"insertDate": {
$gte: ISODate("2019-10-15T15:16:45.328+0000")
}
}
,
{
"insertDate": {
$lte: ISODate("2019-10-15T17:02:44.017+0000")
}
}
]
}
Response:
Script1.groovy: 50: expecting '}', found ':' # line 50, column 25.
"insertDate": {
^
Can someone help in resolving the issue.

Meteor MongoDB Error

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})

Minimongo Error on Serverside Meteor Script?

I'd like to push elements to a mongo array, and I have this query which should would with the current version of meteor mongo (2.6.7).
This is the query:
Coll.upsert({},{ $push: {
'events': {
$each: [{'id': new Mongo.ObjectID, 'start':startDate, ... }],
$sort: {'start': 1}
}
}});
...And here is the minimongo error... Printed to the server console!
I20151117-13:51:54.730(11)? Exception while invoking method 'addReservationTimeslot' MinimongoError: $sort requires $slice to be present
I20151117-13:51:54.731(11)? at MinimongoError (packages/minimongo/packages/minimongo.js:52:1)
I20151117-13:51:54.732(11)? at MODIFIERS.$push (packages/minimongo/packages/minimongo.js:3244:1)
I20151117-13:51:54.732(11)? at packages/minimongo/packages/minimongo.js:3052:1
I20151117-13:51:54.732(11)? at Function._.each._.forEach (packages/underscore/packages/underscore.js:142:1)
I20151117-13:51:54.732(11)? at packages/minimongo/packages/minimongo.js:3027:1
I20151117-13:51:54.732(11)? at Function._.each._.forEach (packages/underscore/packages/underscore.js:142:1)
I20151117-13:51:54.732(11)? at Function.LocalCollection._modify (packages/minimongo/packages/minimongo.js:3020:1)
I20151117-13:51:54.732(11)? at simulateUpsertWithInsertedId (packages/mongo/mongo_driver.js:670:1)
I20151117-13:51:54.732(11)? at [object Object].MongoConnection._update (packages/mongo/mongo_driver.js:537:1)
I20151117-13:51:54.732(11)? at [object Object].<anonymous> (packages/meteor/helpers.js:118:1)
I am probably missing something about the minimongo <-> mongo connection, but how could a server side method be possibly limited by the minimongo implementation?

User Assertion: 1: Update query failed -- RUNNER_DEAD

We are using MongoDB (v2.6.4) to process some data and everything works great except, once in a while, we get a weird RUNNER_DEAD exception...
MongoDB.Driver.WriteConcernException: WriteConcern detected an error ' Update query failed -- RUNNER_DEAD'. (Response was { "lastOp" : { "$timestamp" : NumberLong("6073471510486450182") }, "connectionId" : 49, "err" : " Update query failed -- RUNNER_DEAD", "code" : 1, "n" : 0, "ok" : 1.0 }).
This is the method that causes the exception:
private void UpdateEntityClassName(EntityClassName myEntity) {
var dateTimeNow = DateTime.UtcNow;
var update = Update<EntityClassName>.Set(p => p.Data, myEntity.Data)
...some more Sets...
.Set(p => p.MetaData.LastModifiedDateTime, dateTimeNow);
var result = _myCollection.Update(Query.EQ("_id", myEntity.Identifier), update, UpdateFlags.Upsert);
}
Exception in MongoDB log:
2014-10-23T13:51:29.989-0500 [conn45] update Database.Table query: { _id: "SameID" } update: { $set: { Data: BinData(0, SomeData...), ...more fields... MetaData.LastModifiedDateTime: new Date(1414090294910) } } nmoved:1 nMatched:1 nModified:1 keyUpdates:0 numYields:0 locks(micros) w:2344 2ms
2014-10-23T13:51:29.989-0500 [conn49] User Assertion: 1: Update query failed -- RUNNER_DEAD
2014-10-23T13:51:29.989-0500 [conn46] update Database.Table query: { _id: "SameID" } update: { $set: { Data: BinData(0, SomeData...), ...more fields... MetaData.LastModifiedDateTime: new Date(1414090294926) } } nMatched:1 nModified:1 fastmod:1 keyUpdates:0 numYields:0 locks(micros) w:249 0ms
2014-10-23T13:51:29.989-0500 [conn49] update Database.Table query: { _id: "SameID" } update: { $set: { Data: BinData(0, SomeData...), ...more fields... MetaData.LastModifiedDateTime: new Date(1414090294864) } } nModified:0 keyUpdates:0 exception: Update query failed -- RUNNER_DEAD code:1 numYields:1 locks(micros) w:285 8ms
I found very little documentation about this exception so any help appreciated.
We are running this in a 3 machine replica set if that changes anything.
We've been running this code for a while and we didn't have that issue before (in our original tests) so we went back to MongoDB 2.4.9 (the one we first tested on) and we don't get this exception anymore. Any ideas as to what might have changed that causes this exception?
Why you couldn't use a regular "update" using capped arrays to
limit the size of the array of queries rather than using some custom
logic).
If you have multiple threads that are doing the same thing, your code
doesn't appear thread-safe - let's say that two threads try to update
the same object with _id XYZ but with different changes. Both fetch
the object, both add a new attribute/value to the array and now both
call save - the first one saves, but the second one's save overwrites
the first one.
But that's not likely to be related to your error with RUNNER_DEAD
error - that's more likely a case where either something is killing
the operation or dropping the collection you're writing to (or the
index being used).
Source: #Asya Kamsky's post.