What are you getting now? Are you sure you are only querying this after the user document is available? The user doc is not immediately available on startup. You can also save yourself some typing by using Meteor.user() instead of findOne
By “not work”, do you mean it crashes, or you get undefined?
As I said, the “pendingId” fied is not in the user document automatically. You need to publish it.
You need to read this, it will tell you how to do that:
I’m not sure you are reading what I’m saying here.
Have you published the pendingId field?
Are you doing this query before the user model is available?
Have you looked in your console to see if your program is crashing?
const user = Meteor.user();
// This is basically "if user exists, then get the number of pendingId,
// otherwise return 0 because the user has not been loaded yet.
const count = user ? user.pendingId.length : 0;
Try to do a console.log(Meteor.user()) also to see if the user is actually logged in and loaded
That means you are rendering before the user document has reached the client. You can’t just use minimongo in React components, because it takes time to get data from the server to the client. You need to use WithTracker and pass down the results of database queries to your display components.
The best way would be to use withTracker as as suggested by @jorgeer it would be important to check first if the user object isn’t undefined which happens to be so if the subscription isn’t ready yet.
It is the same, The reason why @jorgeer kept emphasizing on the publish is because getting the length on the client will be affected with how you have published, if you haven’t published and you don’t have auto-publish then you will not be able to get data on the client, make sure your publish the clientId and as I mentioned in my earlier reply check if the object isn’t undefined first.
const user = Meteor.users.findOne({_id: Meteor.userId()});
const pendingId = user ? user.pendingId : null;
console.log(pendingId.length)
Double your schema to check if that pendingId field is there.