Mongodb $ne issue


#1

Hallo @all,

I have a small app where user send to another user tasks. I want to show the user unred tasks with a counter in a button. My Task db object has the following key: value --> readTask: []. If the Id of the user in not inside this array, then he doesn’t read the task. Ok, for this reason I have the following helper:

Template.privateNavbar.helpers({
    'taskcounter': function() {
	var userid = Meteor.user()._id;
	return Task.find({readTask: {$ne: {$in: [userid]}}}).fetch().length;
}
});

but it doesn’t work and I get the following error in my browser console:

Uncaught Error: Can’t create equalityValueSelector for operator object(…)
equalityElementMatcher @ selector.js:233
VALUE_OPERATORS.$ne @ selector.js:388
(anonymous function) @ selector.js:272
.each..forEach @ underscore.js:113
operatorBranchedMatcher @ selector.js:257
compileValueSelector @ selector.js:161
(anonymous function) @ selector.js:140
.each..forEach @ underscore.js:113
compileDocumentSelector @ selector.js:123
_.extend._compileSelector @ selector.js:100
Minimongo.Matcher @ selector.js:43
LocalCollection.Cursor @ minimongo.js:86
LocalCollection.find @ minimongo.js:75
_.extend.find @ collection.js:283
(anonymous function) @ VM1081:2
InjectedScript._evaluateOn @ VM1078:875
InjectedScript._evaluateAndWrap @ VM1078:808
InjectedScript.evaluate @ VM1078:664

and I don’t know why because this db command work in meteor shell. Has anyone an solution for this issue?

ps: Sorry for my bad english.


#2

well, correct operator would be https://docs.mongodb.org/manual/reference/operator/query/nin/
still, you talk about property readTask, but in example only property is “set”


#3

Sorry, I corrected the text.


#4

Thank You shock i will try it out.


#5

You should also use Task.find({..your params}).count() instead of .find().fetch().length as per Meteor docs


#6

Ohh, you are right kzvaigzne. Thank you.