find() and findOne() not working in browser console w/ MeteorJS - meteor

In my browser console Posts works, but I get errors with legitimate _id values with find() or findOne():
Posts.findOne({_id: 5FSZhpYDcq4XWkTva})
VM10024:2 Uncaught SyntaxError: Unexpected identifier
at Object.InjectedScript._evaluateOn (<anonymous>:895:140)
at Object.InjectedScript._evaluateAndWrap (<anonymous>:828:34)
at Object.InjectedScript.evaluate (<anonymous>:694:21)

I couldn't recreate that exact error, but I noticed you don't have quotes around the _id you are searching for.
So instead of this:
Posts.findOne({_id: 5FSZhpYDcq4XWkTva})
try:
Posts.findOne({_id: '5FSZhpYDcq4XWkTva'})

Related

Get error code from AngularFire 2 Auth Signin

Following is my code for user sign-in in ionic2 using AngularFire2 to Firebase.
this.afAuth.auth.signInWithEmailAndPassword(
login.email,
login.password
).catch(ERROR=>{
console.log(ERROR);
});
Here the ERROR variable in catch returns with a code and message. I want to get the code but I see only the following options of ERROR.
message, name and stack.
ERROR.code is not allowed. How do I get the code from ERROR?
Convert the error that is in a primitive format to a more specific one, so you can get more information about it.
.catch ((error: firebase.FirebaseError) => { console.log(error.code)}

Exception in callback of async function: TypeError: callback is not a function

I cant figure out why my insert query code located in server/main.js is causing this: TypeError: callback is not a function error message.
The following code is located at: server/main.js
var businessCard = [{PostedDate: moment().add(0, "days").format('MM/DD/YYYY'), sentBy: currentUserId, recipientName: recipientName }];
Next line is the insert query:
Messages.insert({businessCard: businessCard}, {multi:true});
When I run the code, no inserts into the Messages collection are carried out, neither do I get any error messages in the browser console,
however when I check the terminal I see the following error message:
When I comment out the insert query, the error message disappears, leading me to think there is something wrong in how I have written this insert code.
Kindly help me figure out what am doing wrong here.
Looking forward to your help
The error is because you use multi: true option, insert method does not have this option.

Firebase -- no traceback or line number on error in Chrome

<script src="https://cdn.firebase.com/js/client/2.0.6/firebase.js"></script>
<script>
var root_ref = new Firebase('https://jcatest.firebaseio.com')
function other_function() {
// many lines of code here...
var x = {}
x.x()
// many lines of code here...
}
function my_function(snap){
other_function()
}
root_ref.once('value', my_function)
</script>
If I stick the above code in an html file and open it with Chrome all I see in the console is
"Uncaught TypeError: undefined is not a function ... firebase:26"
In Firefox I see the actual error message:
"TypeError: x.x is not a function ... temp.html:8"
Why am I not seeing the proper error message in Chrome?
Is this a Chrome bug? A Firebase bug? Or am I doing something wrong?
It's a big problem for me because there's a lot of code in my callback and firebase is basically saying, "there's an error somewhere." Not very helpful.
This problem was reproducible on FirebaseJS version 2.0.6. With Firebase 2.2.2, errors and full stacktraces are reported correctly on both browsers.
In the Firebase web client, the Firebase.DataSnapshot object has no method value(), but there is a val() method, which is probably what you're looking for.
See the DataSnapshot docs for more information.
I suspect that the browser is not giving you the relevant error line because the error occurs in an anonymous function, but that's a guess.
If you wrap the callback in a zero ms setTimeout call you get the traceback. Not sure why this is necessary.
root_ref.once('value', function(){ setTimeout(my_function) })

Meteor: Match error: Failed Match.OneOf or Match.Optional validation (websocket)

I have a website that uses Meteor 0.9. I have deployed this website on OpenShift (http://www.truthpecker.com).
The problem I'm experiencing is that when I go to a path on my site (/discover), then sometimes (though not always), the data needed are not fetched by Meteor. Instead I get the following errors:
On the client side:
WebSocket connection to 'ws://www.truthpecker.com/sockjs/796/3tfowlag/websocket' failed: Error during WebSocket handshake: Unexpected response code: 400
And on the server side:
Exception from sub rD8cj6FGa6bpTDivh Error: Match error: Failed Match.OneOf or Match.Optional validation
at checkSubtree (packages/check/match.js:222)
at check (packages/check/match.js:21)
at _.extend._getFindOptions (packages/mongo-livedata/collection.js:216)
at _.extend.find (packages/mongo-livedata/collection.js:236)
at Meteor.publish.Activities.find.user [as _handler] (app/server/publications.js:41:19)
at maybeAuditArgumentChecks (packages/livedata/livedata_server.js:1492)
at _.extend._runHandler (packages/livedata/livedata_server.js:914)
at _.extend._startSubscription (packages/livedata/livedata_server.js:764)
at _.extend.protocol_handlers.sub (packages/livedata/livedata_server.js:577)
at packages/livedata/livedata_server.js:541
Sanitized and reported to the client as: Match failed [400]
Can anyone help me to eliminate this error and get the site working? I'd be very grateful!
Tony
P.S.: I never got this error using localhost.
EDIT:
The line causing the problem the problem is this (line 41):
return Activities.find({user: id}, {sort: {timeStamp: -1}, limit:40});
One document in the activities collection looks like this:
{
"user" : "ZJrgYm34rR92zg6z7",
"type" : "editArg",
"debId" : "wtziFDS4bB3CCkNLo",
"argId" : "YAnjh2Pu6QESzHQLH",
"timeStamp" : ISODate("2014-09-12T22:10:29.586Z"),
"_id" : "sEDDreehonp67haDg"
}
When I run the query done in line 41 in mongo shell, I get the following error:
error: { "$err" : "Unsupported projection option: timeStamp", "code" : 13097 }
I don't really why this is though. Can you help me there as well? Thank you.
Make sure that you are passing an integer to skip and limit. Use parseInt() if need be.
You have a document on your website that does not match your check validation.
The validation you have is in app/server/publications.js:41
So the attribute in question exists in some way like Match.optional(Match.oneOf(xx)) but the document's attribute is neither of the values in Match.oneOf
You would have to go through your documents for the collection causing this and remove or correct the attribute causing this to match your check statement.
Update for your updated question.
You're running Meteor commands in the meteor mongo/mongo shell. The error you get is unrelated to the problem in Meteor, to sort in the mongo shell you would do activities.find(..).sort(), instead of activities.find(.., { sort : {..}). This is unrelated to the issue
The issue is most-likely that your id is not actually a string. Its supposed to be sEDDreehonp67haDg for the document you're looking for. You might want to use the debugger to see what it actually is.
I don't think you can use limit in client-side find queries. Removing limit from my query solves the problem. If you're looking for pagination, then you can either manually roll your own by passing a parameter to your Activities publication so that the limit is added to the server-side query along with an offset. There is also this pagination package.

ydn-db: calling get() for the second time cause error

I read a value from database, then based on that value, I read a second one. Here is the code:
mydb.db.get("store1", 1)
.then(function(result1) {
// Assume result1 is needed here.
// This second get() will cause error.
return mydb.db.get("store2", 1);
})
.then(function(result2) {
// Assume result2 is needed here.
});
The problem is, the second get() will cause this error (copied from console output in Chrome):
Uncaught TypeError: Cannot call method 'push' of undefined (in deferred.js:397)
If I remove the return clause, no error produced but I cannot get the result2.
I am using ydn.db-isw-core-qry.js (production) v0.8.12 with source map, IndexedDB database on Chrome 33.0.1750.149, Windows.
Is there something wrong with my code? Please help.
Thank you.
Here is test http://dev.yathit.com/test/issue_107.html as you described. No error. Please show your code that cause your error.

Resources