Polymer 1.x: $key throws error when saving to Firebase - firebase

I want to save a firebase-document to Firebase. But I encounter the following error.
error.log
Uncaught (in promise) Error: Firebase.push failed: first argument contains an invalid key ($key) in property 'xxxxxxxxxxxx.items'. Keys must be non-empty strings and can't contain ".", "#", "$", "/", "[", or "]"
Here is the relevant code.
my-element.html
<firebase-document id="document" ... ></firebase document>
...
save: function() {
var doc = this.$.document;
console.log('Saved', doc.data);
return doc.save(this.itemsPath).then(function() {
console.log('Saved:', doc);
doc.reset();
}.bind(this));
return Promise.resolve();
},
The data object contains a key label containing the $ character. But this is automatically introduced by Firebase, not a programming decision.
console.log
Saved: {
$key: "foo" // This is the object key in Firebase
...
}
What edits can I make to save my data?

Related

Firestore Error: [cloud_firestore/unknown] Invalid argument (dartObject): Could not convert: Instance of '_FieldValueServerTimestamp'

I'm using flutter and firestore and what I want to do is adding an object as a child inside a list, each time I hit a submit button. Inside that object, I want to have a createdAt field, where the timestamp information should be stored. For that, i'm trying to use FieldValue.serverTimestamp(), but i'm getting the following error.
Uncaught (in promise) Error: [cloud_firestore/unknown] Invalid argument (dartObject): Could not convert: Instance of '_FieldValueServerTimestamp'
The code is as below:
reference.update({
'parentData': FieldValue.arrayUnion([
{
'data': myData,
'createdAt': FieldValue.serverTimestamp()
}
]),
});
I'm also importing the library:
import 'package:cloud_firestore/cloud_firestore.dart';

How to solve error Paths must not contain // in them. Firestore flutter error

I am not including // in my path.But still i am getting error from firestore that Paths must not contain // in them
onPressed: (){
opencheckout();
setState(() {
_firestore.collection('userss').document(uid)
.collection('OrdersSuccess').add({
"name":product.name,
"original":product.original,
"Quantity":product.Quantity,
"image":product.image,
});
});
};
Debug console Message
E/MethodChannel#plugins.flutter.io/cloud_firestore(12572): java.lang.IllegalArgumentException: Invalid path (userss//OrdersSuccess/Iy4M9nYayqCAk0EcCKEB). Paths must not contain // in them.
E/MethodChannel#plugins.flutter.io/cloud_firestore(12572): at com.google.firebase.firestore.model.ResourcePath.fromString(com.google.firebase:firebase-firestore##21.3.0:45)
Read the error message carefully:
Invalid path (userss//OrdersSuccess/Iy4M9nYayqCAk0EcCKEB). Paths must not contain // in them.
Here's the query:
_firestore.collection('userss').document(uid).collection('OrdersSuccess')
It looks like your uid might be an empty string, which causes the two surrounding slashes to collapse into //. So, check uid by using a debugger or printing it, and make sure it contains what you expect.

AWS AppSync - DeleteItem doesn't execute response mapping template

When attempting to delete an item using the following request mapping:
{
"version" : "2017-02-28",
"operation" : "DeleteItem",
"key" : {
"id": { "S" : "$ctx.args.id"},
"sortKey" : { "S" : "$ctx.args.sortKey"}
}
}
If the item exists it will process the result through the response template, however when the item does not exist the response template is never run.
Response template:
#set($ctx.result.status = "SUCCESS")
#set($ctx.result.message = "This was a success!")
$utils.toJson($ctx.result)
I am aware that when an item does not exist in Dynamo it will perform no action but I would expect that it would still process through the template.
Is there anything I am missing or is it impossible for AppSync to processed a DeleteItem request through the response mapping when the document does not exist?
This the expected execution behavior for the version of the template you are using (2017-02-28).
You can switch your request mapping template version to 2018-05-29 and your response mapping template will be executed, with the following characteristics:
If the datasource invocation result is null, the response mapping template is executed.
If the datasource invocation yields an error, it is now up to you to handle the error. The invocation error is accessible using $ctx.error.
The response mapping template evaluated result will always be placed inside the GraphQL response data block. You can also raise or append an error using $util.error() and $util.appendError() respectively.
More info https://docs.aws.amazon.com/appsync/latest/devguide/resolver-mapping-template-changelog.html#aws-appsync-resolver-mapping-template-version-2018-05-29
So for your example:
{
"version" : "2018-05-29", ## Note the new version
"operation" : "DeleteItem",
"key" : {
"id": { "S" : "$ctx.args.id"},
"sortKey" : { "S" : "$ctx.args.sortKey"}
}
}
and response template
#if ( $ctx.error )
$util.error($ctx.error.message, $ctx.error.type)
#end
#set($ctx.result.status = "SUCCESS")
#set($ctx.result.message = "This was a success!")
$utils.toJson($ctx.result)

Meteor Amazon s3 delete image

I have successfully uploaded an image to amazon s3 with this meteor package
https://github.com/Lepozepo/S3 Now I am trying to delete the file, which I am getting a error on.
This is the documentation for the s3.delete code
S3.delete(path,callback)
This function permanently destroys a file located in your S3 bucket.
Parameters:
path: Must be in this format ("/folder/other_folder/file.extension").
So basically always start with "/" and never end with "/". This is
required.
callback: A function that is run after the delete operation
is complete returning an Error as the first parameter (if there is
one), and a Result as the second.
This is my upload and delete code
Template.postSubmit.events({
"click button.upload": function(){
var files = $("input.file_bag")[0].files
S3.upload({
files:files,
path:"uploads"
},function(e,r){
console.log(r);
delete_url = r.relative_url;
console.log(delete_url);
});
},
"click button.delete": function(){
S3.delete({
path:delete_url
},function(e,r){
console.log(e);
console.log(r);
});
}
});
The error I get when hitting the delete button.
errorClass {isClientSafe: true, error: 400, reason: "Match failed", details: undefined, message: "Match failed [400]", …}
details
:
undefined
error
:
400
errorType
:
"Meteor.Error"
isClientSafe
:
true
message
:
"Match failed [400]"
reason
:
"Match failed"
stack
:
"Error↵ at Connection._livedata_result (http://localhost:3000/packages/ddp-client.js?hash=14d966b7972bd95a1f7015fec9ac340f10508a44:4823:23)↵ at onMessage (http://localhost:3000/packages/ddp-client.js?hash=14d966b7972bd95a1f7015fec9ac340f10508a44:3528:206)↵ at http://localhost:3000/packages/ddp-client.js?hash=14d966b7972bd95a1f7015fec9ac340f10508a44:2908:9↵ at Array.forEach (<anonymous>)↵ at Function._.each._.forEach (http://localhost:3000/packages/underscore.js?hash=cde485f60699ff9aced3305f70189e39c665183c:149:11)↵ at SockJS.self.socket.onmessage (http://localhost:3000/packages/ddp-client.js?hash=14d966b7972bd95a1f7015fec9ac340f10508a44:2907:43)↵ at SockJS.REventTarget.dispatchEvent (http://localhost:3000/packages/ddp-client.js?hash=14d966b7972bd95a1f7015fec9ac340f10508a44:142:28)↵ at SockJS._dispatchMessage (http://localhost:3000/packages/ddp-client.js?hash=14d966b7972bd95a1f7015fec9ac340f10508a44:1309:14)↵ at SockJS._didMessage (http://localhost:3000/packages/ddp-client.js?hash=14d966b7972bd95a1f7015fec9ac340f10508a44:1375:26)↵ at WebSocket.that.ws.onmessage (http://localhost:3000/packages/ddp-client.js?hash=14d966b7972bd95a1f7015fec9ac340f10508a44:1531:21)"
__proto__
:
Error
Update
This is the error I got on the server in terminal side
Exception while invoking method '_s3_delete' Error: Match error: Expected string, got object
You should call it like this:
S3.delete(delete_url, function() { ... });
First parameter should be url itself, not the object like in your example.

db.collection.update() throws 'undefined is not a function'

I have this server side method (Meteor method) that successfully finds a document by the ID that it is passed, but when I go to issue a mongo .update(), I get an internal server error (500).
setToggle: function(detailId){
var checked_detail = detailsCollection.findOne({_id: detailId});
checked_detail.update({$set: {checkboxStatus: 'toggle'}});
}
Here is where I initially call the method on the client to create the document:
'submit form': function(ev){
ev.preventDefault();
var detailFormData = {
detail: $(ev.target).find('[name = detail]').val(),
parentId: $(ev.target).find('[name = parentId]').val(),
checkboxStatus: ''
}
Meteor.call('addDetail', detailFormData);
}
And here is that server insert method, so you can see the model:
addDetail: function(detailFormData){
if(! Meteor.userId()){
throw new Meteor.Error('not-authorized');
}
detailsCollection.insert({
detail: detailFormData.detail,
parentId: detailFormData.parentId,
checkboxStatus: detailFormData.checkboxStatus
});
}
Your update syntax is wrong : you're retrieving the Mongo document and then trying to call the update operation on the resulting plain JS object instead of calling the method on the collection itself.
Rewrite your code like this :
setToggle: function(detailId){
detailsCollection.update(detailId,{
$set: {checkboxStatus: 'toggle'}
});
}
The Mongo Collection update syntax takes two (mandatory) parameters :
a Mongo selector to identify which documents in the collection should be updated (on the client using minimongo you're only allowed to modify documents by _id).
a Mongo modifier object to specify how the matching documents should be modified.
https://docs.meteor.com/#/full/update

Resources