That definitely did just help, I can do it inside the Mongo shell no problem now. Still no luck through minimongo, or on the client side. I put it into a Meteor method and it does seem to work there. I am sort of a novice, is there an easier way to do a full text partial string search, or will a meteor method be ok for this?
Minimongo does not support all the MongoDB operators. I checked for $text as an exclusion, but it wasn’t mentioned (but as it was only supported in MongoDB 2.6, that’s not surprising). Short of looking through the source, it’s probably safe to assume from your experiments that it’s not in minimongo.
So, I guess you’ll just have to use a method, unless you wnat to “do it yourself” on the client collection. If the number of documents is large, it’s definitely better on the server, though.
@0mkar and @u2622, you are both talking aboujt something entirely else. What we talk about is support for doing text searches on the client. You are doing the actual searching exclusively on the server.
The reason one would do it on the client as well is to avoid errors. For instance, if you have another publication pushing elements to the same collection, then you would get a lot more objects with your non-exclusive find on the client side - essentially showing too much.
You can also see how not filtering will bring weird results by checking out this gist.
There isn’t any $text support in Minimongo, which means you either have to use Meteor.methods() or be creative I managed to hack around the problem by using a second publication that I store the ids in:
Server side
export const AuditLog = new Mongo.Collection('audit_log');
AuditLog.attachSchema(AuditLogSchema);
AuditLog.ResultIds = new Mongo.Collection('audit_log_results'); // stores results from $text queries
Meteor.publish('auditLog', function(findQuery, options){
const logResults = AuditLog.find(findQuery, options);
// This is a hack to work around the lack of $text support on the client side Minimongo lib
// without which we would have trouble recreating the search results on the client
const key = userId + JSON.stringify(queryOptions); // key that is unique per user and query
const resultIds = logResults.map(e => e._id);
AuditLog.ResultIds.upsert(key, {results: resultIds});
// publish the results to the client side
return [
logResults,
AuditLog.ResultIds.find(key) // ensures the client side can get the indices in the right sort order
];
}
Client side - in the subscription for ‘auditLog’
// We cannot re-use the query as MiniMongo does not support the $text operator!
// Instead of resorting to a Meteor method we can hack around it by relying on an extra
// ad-hoc collection containing the sorted ids ...
const key = Meteor.userId() + JSON.stringify(queryArgs);
const result = AuditLog.ResultIds.findOne(key);
const idsInSortOrder = result.results;
const logsInSortedOrder = idsInSortOrder.map(id => AuditLog.findOne(id));