[JAVA-2259] I can't use $meta operator with $text search and score. Created: 24/Jul/16  Updated: 11/Sep/19  Resolved: 25/Jul/16

Status: Closed
Project: Java Driver
Component/s: Query Operations
Affects Version/s: 3.2.2
Fix Version/s: None

Type: Task Priority: Major - P3
Reporter: Onur Demirta? Assignee: Unassigned
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Java Spring MVC, Mongo Java Driver 3.2.2, Mac OS X El Capitan, Romobongo



 Description   

Hello I have a problem in my Java & mongodb web project. I am using Mongo Java Driver. I am doing text search. However when i use $meta operator with text search it gives this error:
com.mongodb.MongoQueryException: Query failed with error code 2 and error message 'unknown operator: $meta' on server localhost:27017

my code is:

FindIterable<Document> iterable = db.getCollection("users").find(
new Document("$text", new Document("$search", searchInput).append("$caseSensitive", false))
.append("score", new BasicDBObject("$meta", "textScore" )) );



 Comments   
Comment by Jeffrey Yemin [ 25/Jul/16 ]

$meta is a projection operator, not a filter. It can also be used in sorting the results. See this documentation for more details. In Java it will look something like this:

FindIterable<Document> iterable = db.getCollection("users").find(
new Document("$text", new Document("$search", searchInput).append("$caseSensitive", false)))
.project(new Document("score", new Document("$meta", "textScore" )) );

Generated at Thu Feb 08 08:56:44 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.