I am trying to search for the word "credit" in my colloection suing the aggregation framework but I having an error. could anyone help figure out what the issue might be.
db.complaints.createIndex({issue:1})
db.complaints.aggregate([
{$match:{$text:{$search:"credit"}}},
{$project:{issue:1,_id:0}}
])
I am having this error:
assert: command failed: {
"errmsg" : "exception: error processing query: ns=customers.complaints l
imit=0 skip=0\nTree: TEXT : query=credit, language=, tag=NULL\nSort: {}\nProj: {
$textScore: { $meta: \"textScore\" }, issue: 1, _id: 0 }\n planner returned err
or: need exactly one text index for $text query",
"code" : 2,
"ok" : 0
} : aggregate failed
Error: command failed: {
"errmsg" : "exception: error processing query: ns=customers.complaints l
imit=0 skip=0\nTree: TEXT : query=credit, language=, tag=NULL\nSort: {}\nProj: {
$textScore: { $meta: \"textScore\" }, issue: 1, _id: 0 }\n planner returned err
or: need exactly one text index for $text query",
"code" : 2,
"ok" : 0
} : aggregate failed
at Error (<anonymous>)
at doassert (src/mongo/shell/assert.js:11:14)
at Function.assert.commandWorked (src/mongo/shell/assert.js:254:5)
at DBCollection.aggregate (src/mongo/shell/collection.js:1278:12)
at (shell):1:15
2015-09-01T17:10:45.512+0100 E QUERY Error: command failed: {
"errmsg" : "exception: error processing query: ns=customers.complaints l
imit=0 skip=0\nTree: TEXT : query=credit, language=, tag=NULL\nSort: {}\nProj: {
$textScore: { $meta: \"textScore\" }, issue: 1, _id: 0 }\n planner returned err
or: need exactly one text index for $text query",
"code" : 2,
"ok" : 0
} : aggregate failed
at Error (<anonymous>)
at doassert (src/mongo/shell/assert.js:11:14)
at Function.assert.commandWorked (src/mongo/shell/assert.js:254:5)
at DBCollection.aggregate (src/mongo/shell/collection.js:1278:12)
at (shell):1:15 at src/mongo/shell/assert.js:13
If you take a look at your error message then you will see the following message: need exactly one text index for $text query.
Your post shows that you did create an index on issue. However, it appears that you do not have a Text Index declared for your collection.
If you want the issue document field to be text searchable then create a text index as follows:
db.complaints.createIndex({issue:"text"})
(Note, you may only have one text index per collection. However, the fields included in the text index are established upon index creation. Again, see the abovementioned Text Index link.)
This query will work:
db.things.aggregate([{$match:{issue:"credit"}},{$project:{issue:1,_id:0}}])
Related
I have a collection with 300 million documents, each doc has a user_id field like following:
{
"user_id": "1234567",
// and other fields
}
I want to a list of unique user_ids in the collection, but the following mongo shell command results in an error.
db.collection.aggregate([
{ $group: { _id: null, user_ids: { $addToSet: "$user_id" } } }
], { allowDiskUse: true });
2021-11-23T14:50:28.163+0900 E QUERY [js] uncaught exception: Error: command failed: {
"ok" : 0,
"errmsg" : "Error on remote shard <host>:<port> :: caused by :: BSONObj size: 46032166 (0x2BE6526) is invalid. Size must be between 0 and 16793600(16MB) First element: _id: null",
"code" : 10334,
"codeName" : "BSONObjectTooLarge",
"operationTime" : Timestamp(1637646628, 64),
...
} : aggregate failed :
Why does the error occur even with allowDiskUse: true option?
The db version 4.2.16.
You try to insert all unique user_ids in single document , but apparently the size of this document become greater then16MB causing the issue.
distinct may be more useful
db.collection.distinct( "user_id" )
I used MongoDb server version: 4.2.0.
I have Compound index MongoDB:
db.fop.createIndex( { "id":1, "ADDRESS": "text"})
It works:
db.fop.find({"id":{$in:[1]},$text: {$search: "AnyTextSearch"}}, {score: {$meta: "textScore"}}).sort({score:{$meta:"textScore"}})
This does not work:
db.fop.find({"id":{$in:[1,2]},$text: {$search: "AnyTextSearch"}}, {score: {$meta: "textScore"}}).sort({score:{$meta:"textScore"}})
I get an error:
Error: error: {
"ok" : 0,
"errmsg" : "error processing query: ns=osint.fopTree: $and\n id $in [ 1.0 2.0 ]\n TEXT : query=AnyTextSearch, language=english, caseSensitive=0, diacriticSensitive=0, tag=NULL\nSort: { score: { $meta: \"textScore\" } }\nProj: { score: { $meta: \"textScore\" } }\n planner returned error :: caused by :: failed to use text index to satisfy $text query (if text index is compound, are equality predicates given for all prefix fields?)",
"code" : 2,
"codeName" : "BadValue"}
How to make the right request?
if I run sh.status in mongos I get the error:
assert: command failed: {
"ok" : 0,
"errmsg" : "error processing query: ns=config.mongosTree: ping $gt new Date(1532712420740)\nSort: {}\nProj: {}\n No query solutions",
"code" : 2
} : aggregate failed
_getErrorWithCode#src/mongo/shell/utils.js:25:13
doassert#src/mongo/shell/assert.js:16:14
assert.commandWorked#src/mongo/shell/assert.js:290:5
DBCollection.prototype.aggregate#src/mongo/shell/collection.js:1312:5
printShardingStatus#src/mongo/shell/utils_sh.js:611:13
sh.status#src/mongo/shell/utils_sh.js:78:5
#(shell):1:1
2018-07-27T11:28:05.644-0600 E QUERY [thread1] Error: command failed: {
"ok" : 0,
"errmsg" : "error processing query: ns=config.mongosTree: ping $gt new Date(1532712420740)\nSort: {}\nProj: {}\n No query solutions",
"code" : 2
} : aggregate failed :
_getErrorWithCode#src/mongo/shell/utils.js:25:13
doassert#src/mongo/shell/assert.js:16:14
assert.commandWorked#src/mongo/shell/assert.js:290:5
DBCollection.prototype.aggregate#src/mongo/shell/collection.js:1312:5
printShardingStatus#src/mongo/shell/utils_sh.js:611:13
sh.status#src/mongo/shell/utils_sh.js:78:5
I reinstalled all mongo-enterprise packages but still the error persist, all the shards are working correctly, since I can perform find from mongos.
thanks
I am getting error while executing the following command in mongodb:
db.trans.aggregate(
[
{ $match: {"cno":89}},
{ $group: { _id: [ $dateToString: { format: "%Y-%m-%d", date: "$transactiondate" },types:"$type"], count: { $sum: 1 } } }])
I want to group by transaction date and type.
The error is:
assert: command failed: {
"ok" : 0,
"errmsg" : "this object is already an operator expression, and can't be used as a document expression (at 'types')",
"code" : 15990
} : aggregate failed_getErrorWithCode#src/mongo/shell/utils.js:25:13
doassert#src/mongo/shell/assert.js:16:14
assert.commandWorked#src/mongo/shell/assert.js:370:5
DBCollection.prototype.aggregate#src/mongo/shell/collection.js:1319:5
#(shell):1:1
2017-10-24T15:38:35.498+0530 E QUERY [thread1] Error: command failed: {
"ok" : 0,
"errmsg" : "this object is already an operator expression, and can't be used as a document expression (at 'types')",
"code" : 15990
} : aggregate failed :
_getErrorWithCode#src/mongo/shell/utils.js:25:13
doassert#src/mongo/shell/assert.js:16:14
assert.commandWorked#src/mongo/shell/assert.js:370:5
DBCollection.prototype.aggregate#src/mongo/shell/collection.js:1319:5
#(shell):1:1
I have an issue when I try to aggregate results with a geospatial condition :
db.users.group({
reduce: function(obj, prev) {
prev.sums = {
y_levels: prev.sums.y_levels + obj.current_y_level,
x_levels: prev.sums.x_levels + obj.current_x_level,
count: prev.sums.count + 1
}
},
cond: {current_position: { $near: [56.553823, 8.565619, 10]}},
initial: { sums: { y_levels: 0, x_levels: 0, count: 0 } }
});
produces :
uncaught exception: group command failed: {
"errmsg" : "exception: manual matcher config not allowed",
"code" : 13285,
"ok" : 0
I have no issue with a "regular" condition.
Any idea?
I believe that you are seeing this bug here:
http://jira.mongodb.org/browse/SERVER-1742
The bug referenced uses the Map-Reduce command, but "group" is really just a prepared subset of Map-Reduce.
If you need this functionality, please vote it up so that it can be appropriately prioritized.